Adding parameters to a table

A

Andla Rand

Hi,
I'm expecting to get an extra column named 'state' displayed in the
datagrid but it doesnt add one.
Can you please help me find out the problem with the source code.

SqlConnection myConnection = new SqlConnection(
"server=(local);database=demo;Integrated Security=SSPI");

SqlDataAdapter myCommand = new SqlDataAdapter ("select * from demo",
myConnection);

/* myCommand.SelectCommand.Parameters.Add(new SqlParameter("@State",
SqlDbType.NVarChar, 2));
myCommand.SelectCommand.Parameters["@State"].Value = MySelect.Value
*/
try
{
myCommand.SelectCommand.Parameters.Add(new
SqlParameter("@State",SqlDbType.NVarChar,2));
myCommand.SelectCommand.Parameters["@State"].Value = "aa";
}
catch(Exception ex)
{
Response.Write(ex.Message);
}

DataSet ds = new DataSet();
myCommand.Fill(ds, "mytable");

DataGrid1.BorderColor=Color.Black;
DataGrid1.BorderWidth=1;
DataGrid1.GridLines=GridLines.Both;
DataGrid1.CellPadding=3;
DataGrid1.CellSpacing=0;
DataGrid1.HeaderStyle.BackColor=Color.FromArgb(0xaaaadd);

DataGrid1.DataSource=ds.Tables["mytable"].DefaultView;
DataGrid1.DataBind();

Yours sincerely
Andla
 
F

Frank Oquendo

Andla said:
Hi,
I'm expecting to get an extra column named 'state' displayed in the
datagrid but it doesnt add one.

You must have a column in your data source with that name. Additionally, if
you're not generating the table columns at runtime, you must add a column
and bind it to the data coolumn named 'state'.

--
There are 10 kinds of people. Those who understand binary and those who
don't.

http://code.acadx.com
(Pull the pin to reply)
 

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

Similar Threads


Top