By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
455,459 Members | 1,472 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 455,459 IT Pros & Developers. It's quick & easy.

Adding parameters to a table

P: n/a
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(0xa aaadd);

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

Yours sincerely
Andla

*** Sent via Developersdex http://www.developersdex.com ***
Don't just participate in USENET...get rewarded for it!
Nov 15 '05 #1
Share this Question
Share on Google+
1 Reply


P: n/a
Andla Rand wrote:
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)
Nov 15 '05 #2

This discussion thread is closed

Replies have been disabled for this discussion.