473,405 Members | 2,404 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,405 software developers and data experts.

Update Query Error

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
2 1264
Stewart Ross
2,545 Expert Mod 2GB
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
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

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

Similar topics

4
by: Lisa | last post by:
can someone tell me what is wrong with this query? I've tried every combo that I can think of - adding &,"", "'", ) everywhere I can think of and I keep getting an 'Expected end of statement...
2
by: Steve Bishop | last post by:
I'm having problems using an update query. I get the error: Server: Msg 8152, Level 16, State 9, Procedure SP_MemberUpdate, Line 3 String or binary data would be truncated. The statement has been...
6
by: Nicolae Fieraru | last post by:
Hi All, I was trying to update a field in a table, based on the results from a query. The table to be updated is tblCustomers and the query is qrySelect. This query has two parameters, provided...
10
by: Randy Harris | last post by:
I imported records into a table, later found out that many of them had trailing spaces in one of the fields. If I'd caught it sooner, I could have trimmed the spaces before the import. This...
4
by: deko | last post by:
I'm trying to update the address record of an existing record in my mdb with values from another existing record in the same table. In pseudo code it might look like this: UPDATE tblAddress SET...
7
by: Mark Carlyle via AccessMonster.com | last post by:
I have this update query that I am trying to run. I know the syntax is messed up but do not know how to correct it. Select 'UPDATE', Transactions,'Set = where = ' From "Get Daily Balances" ...
6
by: Greg Strong | last post by:
Hello All, In an 'Update' query can you use user-defined functions in the 'Update To' for the query? Either no or I'm missing something. See the additional info below. If I run a query...
0
by: DP | last post by:
hi, i;ve created an update query, which WORKS!!, i've got an update to check a checkbox in a film table, and i've got another update query to uncheck a checkbox, when a record is deleted. ...
2
by: Reedsp | last post by:
OS: MS XP Access version: 2003 SP2 I am trying to use an update query to replace quote marks with nothing. In essence, I'm removing quote marks. I get a error message when a field is empty or...
2
MindBender77
by: MindBender77 | last post by:
Hello again, All... Admin's, I wasn't sure where to post this, please move if in wrong forum. I'm using FrontPage 2003 to post form data to a second form to be used in an update query. The query...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.