winform根据两组条件查询产品价格
选择产地combox1,输入型号textbox1,点击botton1,在textbox2中输出产品价格
数据表名为:价格表
请问要怎么写?
string connectionString = "Data Source=.;Initial Catalog=数据库名;Integrated Security=True"; //这里替换成你的连接字符串
string sql = string.Format("select 价格 from 价格表 where 产地 = '{0}' and 型号 = '{1}'", comboBox1.Text, textBox1.Text);
using (SqlConnection connection = new SqlConnection(connectionString))
{
connection.Open();
using (SqlCommand command = new SqlCommand(sql, connection))
{
object result = command.ExecuteScalar();
if (result != null)
{
textBox2.Text = result.ToString();
}
}
}