![]() | |
![]() |
| | Thread Tools | Search this Thread | Display Modes |
#1
| |||
| |||
|
#2
| |||
| |||
|
|
Hi everyone, I'm having with selecting a row in a datagrid. I have a datagrid that is ment to update and it runs very well, But I don't want the user to keep scrolling when ever they want to update so I created a textbox(txtname) and a button where a user is supposed to write a name and by the click of the button the corresponding row is selected. Now where the problem is it's that when I write a name say Ndayahundwa,Claude and press button I get this error: Incorrect syntax near 'Ndayahundwa'. Here is the code I'm using: SqlCommand myCommand = new SqlCommand(); myCommand.Connection=con; myCommand.CommandText="select * from isp_email.staff where @fullname like%" +txtname.Text+ "%"; SqlParameter myparam = new SqlParameter("@fullname",SqlDbType.Text); myparam.Value=txtname.Text; myCommand.Parameters.Add(myparam); SqlDataAdapter myAdapter=new SqlDataAdapter(myCommand); DataSet ds = new DataSet(); myAdapter.Fill(ds); dgupdate.DataSource=ds; dgupdate.DataBind(); Could some one bail me out? Thanks. I believe the comma in the name is messing up your SQL as it's written. |

#3
| |||
| |||
|
|
Hi everyone, I'm having with selecting a row in a datagrid. I have a datagrid that is ment to update and it runs very well, But I don't want the user to keep scrolling when ever they want to update so I created a textbox(txtname) and a button where a user is supposed to write a name and by the click of the button the corresponding row is selected. Now where the problem is it's that when I write a name say Ndayahundwa,Claude and press button I get this error: Incorrect syntax near 'Ndayahundwa'. Here is the code I'm using: SqlCommand myCommand = new SqlCommand(); myCommand.Connection=con; myCommand.CommandText="select * from isp_email.staff where @fullname like%" +txtname.Text+ "%"; SqlParameter myparam = new SqlParameter("@fullname",SqlDbType.Text); myparam.Value=txtname.Text; myCommand.Parameters.Add(myparam); SqlDataAdapter myAdapter=new SqlDataAdapter(myCommand); DataSet ds = new DataSet(); myAdapter.Fill(ds); dgupdate.DataSource=ds; dgupdate.DataBind(); Could some one bail me out? Thanks. Just a guess but the comma in the name is messing up your SQL as it's |

#4
| |||
| |||
|
|
Hi everyone, I'm having with selecting a row in a datagrid. I have a datagrid that is ment to update and it runs very well, But I don't want the user to keep scrolling when ever they want to update so I created a textbox(txtname) and a button where a user is supposed to write a name and by the click of the button the corresponding row is selected. Now where the problem is it's that when I write a name say Ndayahundwa,Claude and press button I get this error: Incorrect syntax near 'Ndayahundwa'. Here is the code I'm using: SqlCommand myCommand = new SqlCommand(); myCommand.Connection=con; myCommand.CommandText="select * from isp_email.staff where @fullname like%" +txtname.Text+ "%"; SqlParameter myparam = new SqlParameter("@fullname",SqlDbType.Text); myparam.Value=txtname.Text; myCommand.Parameters.Add(myparam); SqlDataAdapter myAdapter=new SqlDataAdapter(myCommand); DataSet ds = new DataSet(); myAdapter.Fill(ds); dgupdate.DataSource=ds; dgupdate.DataBind(); Could some one bail me out? Thanks. |
![]() |
| Thread Tools | Search this Thread |
| Display Modes | |
| |