try to do like this
quotation and concat problem will be solved and is standard one
String st="Insert into info values(@first,@second)";
SqlCommand cmd = new SqlCommand(st, connection);
cmd.Parameters.AddWithValue("@first", TextBox1.Text);
cmd.Parameters.AddWithValue("@second", TextBox2.Text);
If you feel helped. Please mark this post as Answer
Marked as answer by kpawii on Apr 06, 2012 02:47 PM
yeah tdmca has given u an excellent approach, there are soooo many benefits of using this style
i.e. parameterized queries
Make it your style in the coding, and it will benefit u
Error 102 'System.Data.SqlClient.SqlConnection' does not contain a definition for 'ExecuteNonQuery' and no extension method 'ExecuteNonQuery' accepting a first argument of type 'System.Data.SqlClient.SqlConnection' could be found (are you missing a using
directive or an assembly reference?) C:\Users\pawii\Downloads\Compressed\ProfileSample\ProfileSample\insertdata.aspx.cs 31 24 C:\...\ProfileSample\
kpawii
Member
9 Points
25 Posts
semicolon error
Apr 06, 2012 02:25 PM|LINK
protected void Button1_Click(object sender, EventArgs e) { SqlConnection con = new SqlConnection(); con.ConnectionString="Data Source=SQLEXPRESS;AttachDbFilename=|DataDirectory|stu.mdf;Integrated Security=True;User Instance=True"; con.Open(); String st="Insert into info values(" TextBox1.Text + ',' + TextBox2.text "')"; SqlCommand myCom=new SqlCommand(st,con); int numrow=con.ExecuteNonQuery(); con.Close(); }bbcompent1
All-Star
32994 Points
8509 Posts
Moderator
Re: semicolon error
Apr 06, 2012 02:30 PM|LINK
String st="Insert into info values('" TextBox1.Text + "','" + TextBox2.text "')";
Your quote marks have to match. Any text field must have '" + the field.text + "'
TabAlleman
All-Star
15571 Points
2700 Posts
Re: semicolon error
Apr 06, 2012 02:34 PM|LINK
You also left out a couple of plus signs:
String st="Insert into info values('" + TextBox1.Text + "','" + TextBox2.text + "')";
tdmca
Contributor
2396 Points
661 Posts
Re: semicolon error
Apr 06, 2012 02:39 PM|LINK
try to do like this quotation and concat problem will be solved and is standard one String st="Insert into info values(@first,@second)"; SqlCommand cmd = new SqlCommand(st, connection); cmd.Parameters.AddWithValue("@first", TextBox1.Text); cmd.Parameters.AddWithValue("@second", TextBox2.Text);usman400
Contributor
3503 Points
721 Posts
Re: semicolon error
Apr 06, 2012 02:44 PM|LINK
yeah tdmca has given u an excellent approach, there are soooo many benefits of using this style
i.e. parameterized queries
Make it your style in the coding, and it will benefit u
kpawii
Member
9 Points
25 Posts
Re: semicolon error
Apr 06, 2012 02:45 PM|LINK
errror is still there :(
tdmca
Contributor
2396 Points
661 Posts
Re: semicolon error
Apr 06, 2012 02:48 PM|LINK
ya, thanx usman
kpawii
Member
9 Points
25 Posts
Re: semicolon error
Apr 06, 2012 02:51 PM|LINK
kpawii
Member
9 Points
25 Posts
Re: semicolon error
Apr 06, 2012 03:01 PM|LINK
Error 102 'System.Data.SqlClient.SqlConnection' does not contain a definition for 'ExecuteNonQuery' and no extension method 'ExecuteNonQuery' accepting a first argument of type 'System.Data.SqlClient.SqlConnection' could be found (are you missing a using directive or an assembly reference?) C:\Users\pawii\Downloads\Compressed\ProfileSample\ProfileSample\insertdata.aspx.cs 31 24 C:\...\ProfileSample\
this error is generated now
bbcompent1
All-Star
32994 Points
8509 Posts
Moderator
Re: semicolon error
Apr 06, 2012 03:32 PM|LINK
Add a
using System.Data
to your code bheind file.