如下所示,ExecuteScalar属性尚未初始化该怎么解决?

SqlCommand cmd = new SqlCommand("select (select isnull(sum(totalquantity),0) from c_inv_transaction where item_id =" + str + " and lot_No ='" + text + "' and transactionType = 'IN') - (select isnull(sum(totalquantity),0) from c_inv_transaction where item_id =" + str + " and lot_No ='" + text + "' and transactionType = 'OUT') as aa");
this.label4.Text = (string)cmd.ExecuteScalar();

绝地无双
浏览 252回答 2
2回答

HUX布斯

SqlConnection con=new SqlConnection(连接字符串);string sql="select (select isnull(sum(totalquantity),0) from c_inv_transaction where item_id =" + str + " and lot_No ='" + text + "' and transactionType = 'IN') - (select isnull(sum(totalquantity),0) from c_inv_transaction where item_id =" + str + " and lot_No ='" + text + "' and transactionType = 'OUT') as aa";SqlCommand cmd = new SqlCommand(sql,con) //这里的con你没有

BIG阳

SqlCommand中没有指定字符串和CONN连接对象
打开App,查看更多内容
随时随地看视频慕课网APP