Binding the database to the datagrid

Y

yasodhai

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
 
A

Alexey Smirnov

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

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()
 
Y

yasodhai

Thank you very much. Its working fine.


Thanks & Regards,
Yaso

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

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()- Hide quoted text -

- Show quoted text -
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top