p2p.wrox.com Forums

p2p.wrox.com Forums (http://p2p.wrox.com/index.php)
-   BOOK: Professional ASP.NET 4 : in C# and VB (http://p2p.wrox.com/forumdisplay.php?f=554)
-   -   Data Adapter Problems???????? (http://p2p.wrox.com/showthread.php?t=80597)

Mihiran August 20th, 2010 06:25 AM

Data Adapter Problems????????
 
DataTable MyTable = new DataTable();
SqlConnection Conn;
Conn = new SqlConnection(@"Data Source=179-RAKESHP\SQLEXPRESS;Initial Catalog=School;Integrated Security=True;User Instance=True");
Conn.Open();
SqlParameter Countryparam;
SqlCommand MyCommand = new SqlCommand();
MyCommand.CommandText = "SELECT State FROM Table_1 WHERE Country=@Country";
MyCommand.CommandType = CommandType.Text;
MyCommand.Connection = Conn;
SqlDataAdapter MyAdapter= new SqlDataAdapter();
MyAdapter.SelectCommand = MyCommand;
Countryparam = new SqlParameter();
Countryparam.Direction = ParameterDirection.Output;
Countryparam.Value = TextBox8.Text;
DropDownList1.Text = MyCommand.CommandText;
MyAdapter.Fill(MyTable);
DropDownList1.DataSource = MyTable.DefaultView;
DropDownList1.DataBind();
MyCommand.Dispose();
Conn.Dispose();

//I have tried to make a normal connection to Sql Server2008 database by taking the input from a textbox and using it as a parameter for retrieving the data From a tale in database and i wanted to display it in one of my d.down box.........the idea is that if user enters country name,he gets the options of existing states..............can someone please help me get a runnable code........plzzzz

Mihiran August 20th, 2010 06:29 AM

actually im new to asp.net and c#....hope i don't annoy professional programmers by asking a silly question

Imar August 20th, 2010 10:36 AM

Quote:

hope i don't annoy professional programmers by asking a silly question
In that case, you're better off posting in the general ASP.NET 4 Basics or other forum, as your question may be ignored here.

That said, you're creating a Parameter instance but never add it to the Parameters collection of the Command object.

Cheers,

Imar


All times are GMT -4. The time now is 03:21 AM.

Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
© 2013 John Wiley & Sons, Inc.