我在组合框中选择的任何名称都应该反映在文本框中。我是初学者请帮我解决它
public class product
{
public int proid { set; get; }
public string prodname { set; get; }
public int unitprice { set; get; }
}
private void comboBox1_SelectedIndexChanged(object sender, EventArgs e)
{
SqlConnection con = new SqlConnection(@"server=xxxx-PC; database= sample; integrated security= true");
con.Open();
SqlCommand cmd = new SqlCommand("select * from tblproduct ", con);
SqlDataReader dr = cmd.ExecuteReader();
product prod = new product();
while(dr.read())
{
prod.proid = dr[0].ToString();
prod.prodname = dr[1].ToString();
prod.unitprice = dr[2].ToString();
textBox2.Text = proid;
textBox3.Text = prodname;
textBox4.Text = unitprice;
}
}
有错误:
Error : The name 'prodname' does not exist in the current context
Error : Cannot implicitly convert type 'string' to 'int'`improved formatting`