DropDown List help

  • Thread starter Thread starter Dharmen
  • Start date Start date
D

Dharmen

Hey guys!
I wrote a script with 2 dropdown lists. When the value on one is
selected it should automatically load the corresponding value from the table
on the second list. This for some apparent reason is not working.

Label1.Text=this.ddList1.SelectedItem.ToString();
SqlCommand sqlCmd2 =new SqlCommand("SELECT Name FROM pricesTB1 WHERE
Location="+Label1.Text,conn);
conn.Open();
SqlDataReader read2=sqlCmd2.ExecuteReader();
while (read2.Read())
{
//ListItem NewItem2 = new ListItem();
//NewItem2.Text=read2.GetString(0);
//NewItem2.Value = read2.GetValue(0).ToString();
//ddList2.Items.Add(NewItem2);
Label2.Text=this.ddList1.SelectedItem.ToString();
}
conn.Close();

It works fine when i explicitely define the SQL Command but when i read it
using this.ddList1.SelectedItem.ToString();
it messes up...Please help me.
Thanks
 
here is how i am using it in my app and its working fine
=================================================
dataSet2.Clear();

comboBox2.Items.Clear();

this.oleDbSelectCommand2.CommandText = "SELECT Distinct khewatnum FROM
khewat WHERE (mahal = ?)";

this.oleDbSelectCommand2.Connection = this.oleDbConnection1;

this.oleDbSelectCommand2.Parameters.Add(new
System.Data.OleDb.OleDbParameter("mahal",comboBox1.SelectedItem.ToString()))
;

this.oleDbDataAdapter2.Fill(dataSet2 , "mydata2");

for (int i = 0 ; i < dataSet2.Tables["mydata2"].Rows.Count ; i ++ )

{

comboBox2.Items.Add(dataSet2.Tables["mydata2"].Rows.ItemArray.GetValue(0)
);

}

this.oleDbSelectCommand2.Parameters.Clear();

============================================================================
==============
 
Hey Guys...Thanks for the replies!
I still have problems but this time atleast it doesnt gimme any errors...It
jist doesnt enter the while (read2.Read())
loop! I think this is because Im usign sqlCmd.Execute Reader in the first
function and the sqlCmd2.ExecuteReader again.

Is this wrong? or do i have to do anything to close it? I need help in C#
please...i dont know much of VB...If u have MSN ID it would be helpful!
Thanks!
 
Back
Top