110,535
社区成员
发帖
与我相关
我的任务
分享
//你的语句有问题
//实例SqlConnection对象打开数据库连接
SqlConnection conn = new SqlConnection();
conn.ConnectionString = "Server=.;uid=sa;pwd=sa;database=Manager";
conn.Open();
string strselect = "select 库存 from tb_storage where 仓库号='" + textBox1.Text + "' and 设备名称='"+textBox2.Text+"' ";//直接查询库存来
SqlCommand cmd = new SqlCommand(strselect, conn);
SqlDataReader rde = cmd.ExecuteReader();
if(rde.hasRow() && rde.Reade())
{
textbox3.Text=Convert.ToString(rde["库存"]);
MessageBox.Show("库存为:" + rde["库存"].ToString(), "信息", MessageBoxButtons.OK, MessageBoxIcon.Information);
} else
{
MessageBox.Show("输入的仓库号跟设备名称不在表中,无法查询!");
}
rde.Close();
/** int intConut = Convert.ToInt32(cmd.ExecuteScalar().ToString());//查询输入编号是否有效
if (intConut != 0)//编号有效
{
string efg;
efg = "select 库存 from tb_storage where 仓库号='" + textBox1.Text + "' and 设备名称='" + textBox2.Text + "' ";
string efgh = DataTable.Rows[0][0].ToString();
MessageBox.Show("库存为:" + efgh, "信息", MessageBoxButtons.OK, MessageBoxIcon.Information);
}
**/
}