how to update all rows using text box

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • dineshkumar123
    New Member
    • Sep 2014
    • 1

    how to update all rows using text box

    I retrieve all the row values from database into text box.But I could not Update it.It shows error message is
    The variable name '@value' has already been declared. Variable names must be unique within a query batch or stored procedure.
    Must declare the scalar variable "@keyValue" .

    my code is here:

    Code:
    public partial class ECB_ECBConfiguration : System.Web.UI.Page
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            DataTable dt = ECBDal.GetECBConfiguration();
           foreach(DataColumn col in dt.Columns) 
            {
                
                if (dt.Rows.Count > 0)
                {
                    txtECBAddress.Text = dt.Rows[0]["Value"].ToString().Trim();
                    txtECBServer.Text = dt.Rows[1]["Value"].ToString();
                    txtECBEMailID.Text = dt.Rows[2]["Value"].ToString();
                    txtECBContactNo1.Text = dt.Rows[3]["Value"].ToString();
                    txtECBContactNo2.Text = dt.Rows[4]["Value"].ToString();
                    txtECBContactNo3.Text = dt.Rows[5]["Value"].ToString();
                    txtECBContactNo4.Text = dt.Rows[6]["Value"].ToString();
                    txtECBContactNo5.Text = dt.Rows[7]["Value"].ToString();
                }
            }
        }
        protected void btnSave_Click(object sender, EventArgs e)
        {
            using (SqlConnection con = new SqlConnection(ConfigurationManager.AppSettings["MSSQLConnectionString"]))
            {
                SqlCommand cmd = new SqlCommand("UPDATE ECB_Configuration SET [Value] = @value where [Key] = @keyValue", con);
                con.Open();
    
                cmd.Parameters.AddWithValue("@value", txtECBAddress.Text);
                cmd.Parameters.AddWithValue("@value", txtECBServer.Text);
                cmd.Parameters.AddWithValue("@value", txtECBEMailID.Text);
                cmd.Parameters.AddWithValue("@value", txtECBContactNo1.Text);
                cmd.Parameters.AddWithValue("@value", txtECBContactNo2.Text);
                cmd.Parameters.AddWithValue("@value", txtECBContactNo3.Text);
                cmd.Parameters.AddWithValue("@value", txtECBContactNo4.Text);
                cmd.Parameters.AddWithValue("@value", txtECBContactNo5.Text);
                cmd.ExecuteNonQuery();
                ScriptManager.RegisterClientScriptBlock(this, this.GetType(), "alertMessage", "alert('Record Updated Successfully')", true);
                con.Close();
            }
    
        }
        //protected void btnSave_Click(object sender, EventArgs e)
        //{
        //    ECBDal.SaveECBConfiguration();
            
        //}
        
         
    }
    Last edited by Rabbit; Sep 12 '14, 05:02 AM. Reason: Please use [code] and [/code] tags when posting code or formatted data.
  • Rabbit
    Recognized Expert MVP
    • Jan 2007
    • 12517

    #2
    Please use code tags when posting code or formatted data.

    You defined value a bunch of times. And you never define the keyValue variable that you reference in your SQL.

    Comment

    Working...