首页上一页 1 下一页尾页 1 条记录 1/1页
相同的sqlcommand.ExecuteNonQuery()为什么返回的值不一样
发表在C#图书答疑
2011-03-05
是否精华
是
否
版块置顶:
是
否
请看下面代码,注意红色部分
if (intFalg == 1) //intFlag是操作标记,1表示添加
{
//调用jhMenthod类中的tb_JhGoodsInfoMenthodAdd方法,该方法向数据库中添加数据并返回int值
if ([font color=#FF0000]jhMenthod.tb_JhGoodsInfoMenthodAdd(jhGood)==2[/font])
{
MessageBox.Show("添加成功","提示");
intFalg = 0;
jhMenthod.tb_JhGoodsInfoFind("",5,dataGridView1);
ControlStatus();
ClearContorl();
}
else
{
...... }
}
if (intFalg == 2)
{ //调用jhMinthod类中的tb_JhGoodsInfoMenthodUpdate函数
if ([font color=#FF0000]jhMenthod.tb_JhGoodsInfoMenthodUpdate(jhGood)==1[/font])
{
MessageBox.Show("修改成功", "提示");
intFalg = 0;
jhMenthod.tb_JhGoodsInfoFind("", 5, dataGridView1);
ControlStatus();
ClearContorl();
}
else
{
...... }
下面是调用的函数:
public int tb_JhGoodsInfoMenthodAdd(tb_JhGoodsInfo tbGood) //向数据库中添加数据,并返回一个int值作为标记
{
int intFalg = 0;
try
{
string str_Add = "insert into tb_JhGoodsInfo values( ";
str_Add += "'" + tbGood.strGoodsID + "','" + tbGood.strEmpId + "','" + tbGood.strJhCompName + "',";
str_Add += "'" + tbGood.strDepotName + "','" + tbGood.strGoodsName + "','" + tbGood.strGoodsNum + "',";
str_Add += "'" + tbGood.strGoodsUnit + "'," + tbGood.deGoodsJhPrice + " ," + tbGood.deGoodsSellPrice + " ,";
str_Add += "" + tbGood.deGoodsNeedPrice + "," + tbGood.deGoodsNoPrice + ",'" + tbGood.strGoodsRemark + "',";
str_Add += "'" + tbGood.DaGoodTime + "'," + tbGood.Falg + ")";
getSqlConnection getConnection = new getSqlConnection();
conn = getConnection.GetCon();
cmd = new SqlCommand(str_Add, conn);
intFalg = cmd.ExecuteNonQuery(); // [font color=#FF0000]这里应该是2才对,可是明明只添加了一行为什么返回的是2?可下面同样的语句为什么返回的是1
[/font]
conn.Dispose();
return intFalg;
这是另一个函数:
public int tb_JhGoodsInfoMenthodUpdate(tb_JhGoodsInfo tbGood)
{
int intFalg = 0;
try
{
string str_Add = "update tb_JhGoodsInfo set ";
str_Add += "EmpId='" + tbGood.strEmpId + "',JhCompName='" + tbGood.strJhCompName + "',";
str_Add += "DepotName='" + tbGood.strDepotName + "',GoodsName='" + tbGood.strGoodsName + "',GoodsNum='" + tbGood.strGoodsNum + "',";
str_Add += "GoodsUnit='" + tbGood.strGoodsUnit + "',GoodsJhPrice=" + tbGood.deGoodsJhPrice + " ,GoodsSellPrice=" + tbGood.deGoodsSellPrice + " ,";
str_Add += "GoodsNeedPrice=" + tbGood.deGoodsNeedPrice + ",GoodsNoPrice=" + tbGood.deGoodsNoPrice + ",GoodsRemark='" + tbGood.strGoodsRemark + "',";
str_Add += "GoodTime='" + tbGood.DaGoodTime + "',Falg='" + tbGood.Falg + "' where GoodsID ='" + tbGood.strGoodsID + "'";
getSqlConnection getConnection = new getSqlConnection();
conn = getConnection.GetCon();
cmd = new SqlCommand(str_Add, conn);
intFalg = cmd.ExecuteNonQuery();[font color=#FF0000]//这里cmd.ExecuteNonQuery()的值是1,可和上面的为什么不一样?
[/font] conn.Dispose();
return intFalg;
请指教,谢谢!
if (intFalg == 1) //intFlag是操作标记,1表示添加
{
//调用jhMenthod类中的tb_JhGoodsInfoMenthodAdd方法,该方法向数据库中添加数据并返回int值
if ([font color=#FF0000]jhMenthod.tb_JhGoodsInfoMenthodAdd(jhGood)==2[/font])
{
MessageBox.Show("添加成功","提示");
intFalg = 0;
jhMenthod.tb_JhGoodsInfoFind("",5,dataGridView1);
ControlStatus();
ClearContorl();
}
else
{
...... }
}
if (intFalg == 2)
{ //调用jhMinthod类中的tb_JhGoodsInfoMenthodUpdate函数
if ([font color=#FF0000]jhMenthod.tb_JhGoodsInfoMenthodUpdate(jhGood)==1[/font])
{
MessageBox.Show("修改成功", "提示");
intFalg = 0;
jhMenthod.tb_JhGoodsInfoFind("", 5, dataGridView1);
ControlStatus();
ClearContorl();
}
else
{
...... }
下面是调用的函数:
public int tb_JhGoodsInfoMenthodAdd(tb_JhGoodsInfo tbGood) //向数据库中添加数据,并返回一个int值作为标记
{
int intFalg = 0;
try
{
string str_Add = "insert into tb_JhGoodsInfo values( ";
str_Add += "'" + tbGood.strGoodsID + "','" + tbGood.strEmpId + "','" + tbGood.strJhCompName + "',";
str_Add += "'" + tbGood.strDepotName + "','" + tbGood.strGoodsName + "','" + tbGood.strGoodsNum + "',";
str_Add += "'" + tbGood.strGoodsUnit + "'," + tbGood.deGoodsJhPrice + " ," + tbGood.deGoodsSellPrice + " ,";
str_Add += "" + tbGood.deGoodsNeedPrice + "," + tbGood.deGoodsNoPrice + ",'" + tbGood.strGoodsRemark + "',";
str_Add += "'" + tbGood.DaGoodTime + "'," + tbGood.Falg + ")";
getSqlConnection getConnection = new getSqlConnection();
conn = getConnection.GetCon();
cmd = new SqlCommand(str_Add, conn);
intFalg = cmd.ExecuteNonQuery(); // [font color=#FF0000]这里应该是2才对,可是明明只添加了一行为什么返回的是2?可下面同样的语句为什么返回的是1
[/font]
conn.Dispose();
return intFalg;
这是另一个函数:
public int tb_JhGoodsInfoMenthodUpdate(tb_JhGoodsInfo tbGood)
{
int intFalg = 0;
try
{
string str_Add = "update tb_JhGoodsInfo set ";
str_Add += "EmpId='" + tbGood.strEmpId + "',JhCompName='" + tbGood.strJhCompName + "',";
str_Add += "DepotName='" + tbGood.strDepotName + "',GoodsName='" + tbGood.strGoodsName + "',GoodsNum='" + tbGood.strGoodsNum + "',";
str_Add += "GoodsUnit='" + tbGood.strGoodsUnit + "',GoodsJhPrice=" + tbGood.deGoodsJhPrice + " ,GoodsSellPrice=" + tbGood.deGoodsSellPrice + " ,";
str_Add += "GoodsNeedPrice=" + tbGood.deGoodsNeedPrice + ",GoodsNoPrice=" + tbGood.deGoodsNoPrice + ",GoodsRemark='" + tbGood.strGoodsRemark + "',";
str_Add += "GoodTime='" + tbGood.DaGoodTime + "',Falg='" + tbGood.Falg + "' where GoodsID ='" + tbGood.strGoodsID + "'";
getSqlConnection getConnection = new getSqlConnection();
conn = getConnection.GetCon();
cmd = new SqlCommand(str_Add, conn);
intFalg = cmd.ExecuteNonQuery();[font color=#FF0000]//这里cmd.ExecuteNonQuery()的值是1,可和上面的为什么不一样?
[/font] conn.Dispose();
return intFalg;
请指教,谢谢!