特定の列テキストのデータを別の列からクエリしようとしています。
基本的に、SupplierID と Country 列を持つサプライヤ データベースがあります。
たとえば、その特定の行の SupplierID は既にあります。14 です。14 の値に基づいて Country 列のテキスト値を取得したいと思います。
次のコード (リストボックス) で取得しているサプライヤー ID:
<asp:ListBox ID="SupplierListBox" runat="server"
DataSourceID="SupplierCompanyDataSource" DataTextField="Company"
DataValueField="SupplierID" Width="315px"
Height="80px"
onselectedindexchanged="SupplierListBox_SelectedIndexChanged"
AutoPostBack="True"></asp:ListBox>
コード:
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();