By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
424,686 Members | 2,708 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 424,686 IT Pros & Developers. It's quick & easy.

Update Query Error

P: 2
When i am running this query its gvng an syntax error near where statement..
Expand|Select|Wrap|Line Numbers
  1. SqlCommand cmd2 = new SqlCommand("Update Personal_Profile set city='" + txtcity.Text + "',"+"hometown='" + txttown.Text + "',"+"iam='" + gender + "',"+"interestedin='" + interested + "',"+"languages='" + txtlang.Text + "',"+"aboutme='" + txtabtme.Text + "',"+"phno='" + txtmobileph.Text + "relationship='" + relationship +"','"+"where (username = '"+unm +"')", con);
  2. cmd2.ExecuteNonQuery();
  3.  
May 23 '11 #1
Share this Question
Share on Google+
2 Replies


Expert Mod 2.5K+
P: 2,545
You have an error in the separators between parts just after the phone number.

You have this at present:

Expand|Select|Wrap|Line Numbers
  1. +"phno='" + txtmobileph.Text + "relationship='" + relationship +"','"+"where (username = '"+unm +"')"
but it should be

Expand|Select|Wrap|Line Numbers
  1. +"phno='" + txtmobileph.Text + "', relationship='" + relationship +"' WHERE (username = '"+unm +"')"
-Stewart
May 23 '11 #2

P: 2
Thnks... D error has been removed .. But d values are still not being updated...

Expand|Select|Wrap|Line Numbers
  1.    protected void Button1_Click(object sender, EventArgs e)
  2.     {
  3.         con = new SqlConnection(cns);
  4.         string unm = Session["uname"].ToString();
  5.         string gender;
  6.         gender = DropDownList1.SelectedValue.ToString();
  7.         string interested;
  8.         if (chkmale.Checked == true)
  9.             interested = "male";
  10.         else
  11.             interested = "female";
  12.         string relationship;
  13.         relationship = DropDownList2.SelectedValue.ToString();
  14.         con.Open();
  15.         SqlCommand cmd1 = new SqlCommand("Select * from Personal_Profile where username ='" + unm + "'", con);
  16.         SqlDataReader dr = cmd1.ExecuteReader();
  17.         if (dr.Read())
  18.         {
  19.             if (dr.HasRows == false)
  20.             {
  21.                 cmd = new SqlCommand("insert into Personal_Profile values('" + unm + "','" + txtcity.Text + "','" + txttown.Text + "','" + gender + "','" + interested + "','" + txtlang.Text + "','" + txtabtme.Text + "','" + txtmobileph.Text + "','" + relationship + "')", con);
  22.                 cmd.ExecuteNonQuery();
  23.             }
  24.             else
  25.             {
  26.                 con.Close();
  27.                 con.Open();
  28.                 SqlCommand cmd2 = new SqlCommand("Update Personal_Profile set city='" + txtcity.Text + "',"+"hometown='" + txttown.Text + "',"+"iam='" + gender + "',"+"interestedin='" + interested + "',"+"languages='" + txtlang.Text + "',"+"aboutme='" + txtabtme.Text + "',"+"phno='" + txtmobileph.Text + "',relationship='" + relationship +"'where username = '"+unm +"'", con);
  29.                 cmd2.ExecuteNonQuery();
  30.                 con.Close();
  31.             }
  32.         }
  33.     }
May 23 '11 #3

Post your reply

Sign in to post your reply or Sign up for a free account.