View Single Post
  #1 (permalink)  
Old August 20th, 2010, 06:25 AM
Mihiran Mihiran is offline
Registered User
 
Join Date: Aug 2010
Posts: 2
Thanks: 0
Thanked 0 Times in 0 Posts
Default 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