Groups | Blog | Home
all groups > asp.net > march 2007 >

asp.net : Binding the database to the datagrid


yasodhai NO[at]SPAM gmail.com
3/11/2007 11:53:26 PM
Hi,
I retrieved the value of the session varible SID and i convert it to
the integer variable called sid. I thought of retrieving the rows
which correspond to this varible "sid"

string secid=Session["SID"].ToString();
int sid=Convert.ToInt32(secid);

Hence I have to pass the variable "sid" to the where clause in the
select statement. I used "&" but it displays error message "Incorrect
Syntax near &".


SqlDataAdapter Fld = new SqlDataAdapter("select * from Fielddet where
SectionID=&sid& ", myConnection);
try
{
myConnection.Open();
}
catch(Exception e)
{
Console.WriteLine(e.ToString());
}

DataSet Fldds=new DataSet();
Fld.Fill(Fldds,"Fielddet");
DataGrid_Fields.DataSource=Fldds.Tables["Fielddet"];
DataGrid_Fields.DataBind();
myConnection.Close();

Kindly help me how to do this..

Thanks & Regards,
Yasodhai
Alexey Smirnov
3/12/2007 12:29:19 AM
[quoted text, click to view]

This

"select * from Fielddet where SectionID=&sid& "

is wrong.

Must be something like

"select * from Fielddet where SectionID=" + secid

or

"select * from Fielddet where SectionID=" + sid.ToString()
yasodhai NO[at]SPAM gmail.com
3/12/2007 3:25:48 AM
Thank you very much. Its working fine.


Thanks & Regards,
Yaso

On Mar 12, 12:29 pm, "Alexey Smirnov" <alexey.smir...@gmail.com>
[quoted text, click to view]

AddThis Social Bookmark Button