HighTechTalks DotNet Forums  

updating a row in datagrid..

ASP.net Data Grid Control microsoft.public.dotnet.framework.aspnet.datagridcontrol


Discuss updating a row in datagrid.. in the ASP.net Data Grid Control forum.



Reply
 
Thread Tools Search this Thread Display Modes
  #1  
Old   
rcoco
 
Posts: n/a

Default updating a row in datagrid.. - 01-11-2007 , 02:18 AM






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.


Reply With Quote
  #2  
Old   
WhoKnows
 
Posts: n/a

Default Re: updating a row in datagrid.. - 01-13-2007 , 07:47 AM






In article <1168499932.862988.198330 (AT) o58g2000hsb (DOT) googlegroups.com>,
nclauder (AT) yahoo (DOT) ca says...
Quote:
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.
I'm not sure why you are passing a parameter. Your SQL is written and
stored in your commandtext so you really don't need it. If you chage
the like clause to
like '%" + txtname.Text + "%'"
the query will run a lot better!!


Reply With Quote
  #3  
Old   
WhoKnows
 
Posts: n/a

Default Re: updating a row in datagrid.. - 01-13-2007 , 07:48 AM



In article <1168499932.862988.198330 (AT) o58g2000hsb (DOT) googlegroups.com>,
nclauder (AT) yahoo (DOT) ca says...
Quote:
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
written. I'm not sure why you are passing a parameter. Your SQL is
written and stored in your commandtext so you really don't need it. If
you re-code the like clause to
like '%" + txtname.Text + "%'"
the query will run a lot better!!


Reply With Quote
  #4  
Old   
WhoKnows
 
Posts: n/a

Default Re: updating a row in datagrid.. - 01-13-2007 , 07:56 AM



In article <1168499932.862988.198330 (AT) o58g2000hsb (DOT) googlegroups.com>,
nclauder (AT) yahoo (DOT) ca says...
Quote:
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.


LOL Fat fingers!!! I think this will work better. Sorry for the
confusion.
like '% + txtname.Text + %'"


Reply With Quote
Reply




Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off



Powered by vBulletin Version 3.5.4
Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.