I am trying to query data of a specific column text from another column.
Basically, I have a Supplier Database that has a SupplierID and Country column.
I already have the SupplierID for that specific row for example, it is 14. I would like to get the text value of Country column based on the 14 value.
The Supplier ID I am getting by the following code (listbox):
<asp:ListBox ID="SupplierListBox" runat="server"
DataSourceID="SupplierCompanyDataSource" DataTextField="Company"
DataValueField="SupplierID" Width="315px"
Height="80px"
onselectedindexchanged="SupplierListBox_SelectedIndexChanged"
AutoPostBack="True"></asp:ListBox>
Code:
string SupplierListvalue = SupplierListBox.SelectedItem.Value; //SupplierListvalue retrieves the SupplierID value
SqlDataReader rdr = null;
SqlConnection conn = new SqlConnection("Data Source=localhost;Initial Catalog=ROG;Integrated Security=True");
SqlCommand cmd = new SqlCommand("select Country from SupplierDB", conn);
cmd.Connection = conn;
conn.Open();
rdr = cmd.ExecuteReader();
while (rdr.Read())
{
TextBox1.Text = rdr["Country"].ToString();
MessageBox.Show("Connection Successful");
MessageBox.Show(rdr.ToString());
}
conn.Close();
"SELECT country FROM myTable WHERE SupplierID=14"?SelectCommand="SELECT [Company], [SupplierID] FROM [SupplierDB] WHERE ([SupplierID] >= @SupplierID)"> <SelectParameters><asp:Parameter DefaultValue="14" Name="SupplierID" Type="Int32" /> //defaultvalue="14" is the starting value in the database SelectCommand="SELECT [SupplierID], [Country] FROM [SupplierDB] WHERE ([SupplierID] = @SupplierID)"> <asp:ControlParameter ControlID="SupplierListBox" Name="SupplierID" PropertyName="SelectedValue" Type="Int32" />