根据组合框选择显示文本框值

Show textbox values depending upon combobox selection

在 SQL 我有列 price(nchar(10)), product_category(nvarchar(50)) 我想在 select 从组合框中输入项目后,将 sql 的价格显示到某个文本框。出现连续错误,当我尝试 GETOrdinal("ColumnName") 时,当我从组合框 select 时,它在文本框中仅显示 0 请带我离开这里。提前致谢

private void cb_ocat_SelectedIndexChanged_1(object sender, EventArgs e)
{
    using (SqlConnection sqlConnection = new SqlConnection(@"Data Source=.;Initial Catalog=Pizza Mania;Integrated Security=True"))
    {
        using (SqlCommand sqlCmd2 = new SqlCommand("select Distinct(Price) from product where Product_category='" + cb_ocat.Text + "'", sqlConnection))
        {
            sqlConnection.Open();

            SqlDataReader sqlrdr = sqlCmd2.ExecuteReader();


            while (sqlrdr.Read())
            {
                String price = sqlrdr.GetInt32("Price").ToString();//getting error here that dbdatareader(int) has some invalid arguments
                txt_oprice.Text = price;
            }
            sqlConnection.Close();
        }
    }
}

试试这个..

while (sqlrdr.Read())
                {
                    String price = sqlrdr["Price"].ToString();//getting error here that dbdatareader(int) has some invalid arguments
                    txt_oprice.Text = price;
                }