Click here to Skip to main content
15,881,380 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
C#
protected void Button_update_Click(object sender, EventArgs e)
        {
            conn.Open();
            string updateQuery = "update emp_details(emp_name,father_name,age,sex,dob,nationality,state,city,mobile_no,exp,qual,emp_sal,email) values(@name,@fname,@age,@sex,@dob,@nation,@state,@city,@mob,@exp,@qual,@sal,@email) ";
            SqlCommand com = new SqlCommand(updateQuery, conn);

            com.Parameters.AddWithValue("@name", TextBox_emp_name.Text);
            com.Parameters.AddWithValue("fname", TextBox_father_name.Text);
            com.Parameters.AddWithValue("@age", TextBox_Age.Text);
            com.Parameters.AddWithValue("@sex", RadioButtonList_sex.Text);// is this NOTATAION correct of selecting Dropdownlist
            com.Parameters.AddWithValue("@dob", TextBox_dob.Text);
            com.Parameters.AddWithValue("@nation", TextBox_nationality.Text);
            com.Parameters.AddWithValue("@state", TextBox_state.Text);
            com.Parameters.AddWithValue("@city", TextBox_city.Text);
            com.Parameters.AddWithValue("@mob", TextBox_mob.Text);
            com.Parameters.AddWithValue("@exp", DropDownList_exp.Text);
            com.Parameters.AddWithValue("@qual", DropDownList_qual.Text);
            com.Parameters.AddWithValue("@sal", TextBox_sal.Text);
            com.Parameters.AddWithValue("@email", TextBox_email.Text);
            com.ExecuteNonQuery();
            conn.Close();---------------->here it is showing an error"incorrect syntax near'(' "
            Response.Write("Updation Succesfull");
        }
Posted
Updated 9-Apr-15 10:09am
v4
Comments
Maciej Los 9-Apr-15 15:36pm    
What's the question?
Member 11586797 9-Apr-15 15:38pm    
i am running ds update query and on update click event it is showng an error dat incorrect syntax near'('

1 solution

The proper update command[^] is:
SQL
UPDATE TableName SET FieldName = Something
WHERE AnotherFieldName = criteria


Sounds like you want to insert data. If yes, then replace UPDATE with
SQL
INSERT INTO TableName (<FieldList>)
VALUES(<Values>)
 
Share this answer
 
v2
Comments
Member 11586797 9-Apr-15 15:43pm    
how can i do it in aspx.cs code??
Maciej Los 9-Apr-15 15:44pm    
The same you're doing it now ;)
Member 11586797 9-Apr-15 15:47pm    
no i want to update only few data among the all..so i have to use update query
Member 11586797 9-Apr-15 15:48pm    
---
Member 11586797 9-Apr-15 15:49pm    
string updateQuery = "update emp_details(emp_name,father_name,age,sex,dob,nationality,state,city,mobile_no,exp,qual,emp_sal,email) values(@name,@fname,@age,@sex,@dob,@nation,@state,@city,@mob,@exp,@qual,@sal,@email) ";

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900