Well, as bpd said, first you should remove @.
Then, after line: "myAdapter.Fill ..." ...
there is no need to perform opening con, executing command and closing con
again,
(unless you are trying to do something else with that?)
adapter should do it for you, but there is nothing wrong if you are opening
and closing manually.
So, your try block should be something like this...
try
{
con.Open(); // Assuming that con object is properly created with correct
connection string
SqlCommand myCommand = new SqlCommand();
myCommand.Conne ction=con;
myCommand.Comma ndText="SELECT * from employee where fullname Like %" +
txtname.Text + "%";
SqlDataAdapter myAdapter=new SqlDataAdapter( myCommand);
DataSet ds = new DataSet();
myAdapter.Fill( ds,"isp_email.s taff");
con.Close();
dgupdate.DataSo urce=ds;
dgupdate.DataBi nd();
}
"bpd" <br*********@ro llcoater.comwro te in message
news:11******** **************@ i56g2000hsf.goo glegroups.com.. .
>I believe you just need to remove the @ in front of txtname.text.
rcoco wrote:
>Thanks,
the whole code actually goes like this as per now hope you could hlp
me:
try
{
con.Open();
SqlCommand myCommand = new SqlCommand();
myCommand.Conn ection=con;
myCommand.Comm andText="SELECT * from employee where fullname Like
%"+@txtname.Te xt+"%";
SqlDataAdapt er myAdapter=new SqlDataAdapter( myCommand);
DataSet ds = new DataSet();
myAdapter.Fill (ds,"isp_email. staff");
con.Open();
myCommand.Exec uteNonQuery();
dgupdate.DataS ource=ds;
dgupdate.DataB ind();
con.Close();
}
catch(Exceptio n err)
{
Console.WriteL ine(err.Message );
}
finally
{
con.Close();
}
Thank you