当前位置:编程学习 > C#/ASP.NET >>

C#+ACCESS的仓库管理系统问题~头痛,

private void btAdd_Click(object sender, System.EventArgs e)
{
if (comMID.Text.Trim()=="")
MessageBox.Show("请填写物资编号!","提示");
else
{
oleConnection1.Open();
string sql = "select * from ininfo where MID='"+comMID.Text.Trim()+"'";
this.oleCommand1.CommandText = sql;

if (null == oleCommand1.ExecuteScalar())
{
string sql1 = "insert into ininfo (MID,InAccount,InPrice,InValue,InDate,InDealer,InSaver,InStore,Remark) values "+
"('"+comMID.Text.Trim()+"','"+textAccount.Text.Trim()+"',"+
"'"+textPrice.Text.Trim()+"','"+textValue.Text.Trim()+"','"+date1.Text.Trim().Substring(0,date1.Text.Trim().IndexOf(' '))+"','"+textDealer.Text.Trim()+"',"+
"'"+textSaver.Text.Trim()+"','"+textStore.Text.Trim()+"','"+textRemark.Text.Trim()+"')";
oleCommand1.CommandText=sql1;
oleCommand1.ExecuteNonQuery();
MessageBox.Show("添加入库信息成功!","提示");
this.Close();

else
MessageBox.Show("物资编号"+comMID.Text.Trim()+"已经存在!","警告");
oleConnection1.Close();
}
}


只能入库一次,再次入库相同的物品编号就直接执行了ELSE语句,哪位大神帮小弟修改修改,感激不尽,相同物品多次入库就行~~并且能叠加 --------------------编程问答-------------------- 在数据库里面取消 MID 为主键,去除唯一性约束。

if (null == oleCommand1.ExecuteScalar())
=>
if (null == oleCommand1.ExecuteScalar() || true )
--------------------编程问答--------------------

//第一次是添加
//第二次是叠加
//要叠加就在else里增加一条修改语句就行了
else
{
string sql1 = "update ininfo set InAccount='"+textAccount.Text.Trim()+"',
InPrice="'"+textPrice.Text.Trim()+"' where MID='"+comMID.Text.Trim()+"';
oleCommand1.CommandText=sql1;
int i=oleCommand1.ExecuteNonQuery();
if(i>0)
{
MessageBox.Show("添加入库信息成功!","提示");
}
else
{
MessageBox.Show("添加入库信息失败!","提示");

}
}
--------------------编程问答-------------------- 修改语句有点问题,
要叠加原来的值

引用 2 楼 ohkuy 的回复:
C# code

//第一次是添加
//第二次是叠加
//要叠加就在else里增加一条修改语句就行了
else
{
//注意,什么值需要叠加就加什么值,如数量,价格等,还要注意格式转化
string sql1 = "update ininfo set InAccount=InAccount+"+textAccount.Text.Trim()+",
InPrice=InPrice+"+textPrice.Text.Trim()+" where MID='"+comMID.Text.Trim()+"';
oleCommand1.CommandText=sql1;
int i=oleCommand1.ExecuteNonQuery();
if(i>0)
{
MessageBox.Show("添加入库信息成功!","提示");
}
else
{
MessageBox.Show("添加入库信息失败!","提示");

}
}
--------------------编程问答-------------------- 除
补充:.NET技术 ,  C#
CopyRight © 2012 站长网 编程知识问答 www.zzzyk.com All Rights Reserved
部份技术文章来自网络,