Assume i have a table
field1, field2, field3
and i have radio button list that displaying field1, field2, field3

If the end-user selected field2 and inserting a value into field2
How can i do? Any Tricks?
Thanks for in advance.

Re: SQL DATABASE how to insert based on end-user selected field? 80 80

Well done on self-answering, but would you care to share your solution incase another user runs into the same issue?


Re: SQL DATABASE how to insert based on end-user selected field? 80 80
        protected void AddTransaction(object sender, EventArgs e)
            double amount = Convert.ToDouble(txtAmount.Text) + isContainValue();

            SqlConnection conAddTransaction = new SqlConnection(ConfigurationManager.ConnectionStrings["connMSJ"].ConnectionString);
            SqlCommand cmdUpdateTransaction = new SqlCommand(String.Format("UPDATE DailyBudget SET {0}=@amount WHERE (Username=@username AND Date=@date)", radCategory.SelectedValue), conAddTransaction);
            SqlCommand cmdAddTransaction = new SqlCommand(String.Format("INSERT INTO DailyBudget (Username, Date, {0}) VALUES (@username, @date, @amount)", radCategory.SelectedValue), conAddTransaction);
            cmdUpdateTransaction.Parameters.AddWithValue("@username", Master.getUsername);
            cmdUpdateTransaction.Parameters.AddWithValue("@date", DateTime.Now.Date);
            cmdUpdateTransaction.Parameters.AddWithValue("@amount", amount);

            cmdAddTransaction.Parameters.AddWithValue("@username", Master.getUsername);
            cmdAddTransaction.Parameters.AddWithValue("@date", DateTime.Now.Date);
            cmdAddTransaction.Parameters.AddWithValue("@amount", amount);
            if (totalUsage != 0)

            totalUsage += Convert.ToDouble(txtAmount.Text);

Sorry for that. Happy Coding Folks

Re: SQL DATABASE how to insert based on end-user selected field? 80 80

Cheers Gahhon!

Be a part of the DaniWeb community

We're a friendly, industry-focused community of 1.19 million developers, IT pros, digital marketers, and technology enthusiasts learning and sharing knowledge.