SqlConnection sqlct = new SqlConnection(@"Data Source=.\SQLEXPRESS;AttachDbFilename=|DataDirectory|\Data\StoreMIS.mdf;Integrated Security=True;User Instance=True");
if (comMID.Text.Trim() == "")
{
MessageBox.Show("请填写物资编号!", "提示");
}
else
{
sqlct.Open();
SqlCommand cmd = new SqlCommand("", sqlct);
string sql = "select * from ininfo where MID= '" + comMID.Text.Trim() + " ' ";
cmd.CommandText = sql;
if (null == cmd.ExecuteScalar())
{
string sql1 = "insert into ininfo (MID,InAccount,InPrice,InValue,InDate,InDealer,InSaver,InStore,Re) values " + "('" + comMID.Text.Trim() + " ' , ' " +
textAccount.Text.Trim() + " '," + " ' " + textPrice.Text.Trim() + " ' , ' " + textValue.Text.Trim() + " ' , ' " + date1.Text.Trim() + " ' , ' " + textDealer.Text.Trim() + " ' , " + " ' " +
textSaver.Text.Trim() + " ' , ' " + textStore.Text.Trim() + " ' , ' " + textRe.Text.Trim() + "')";
cmd.CommandText = sql1;
cmd.ExecuteNonQuery();//列名 'InDate' 无效。
MessageBox.Show("添加入库信息成功!","提示");
this.Close();
}
else
{
MessageBox.Show("物资编号" + comMID.Text.Trim() +"已经存在!","警告");
sqlct.Close();
}
怎么会列名无效呢 是不是存储语句错呢?
求高手解决 实在是不解决不了了 谢谢啦 数据库中有这一列的 类型是:datetime 求高手 谢谢
if (comMID.Text.Trim() == "")
{
MessageBox.Show("请填写物资编号!", "提示");
}
else
{
sqlct.Open();
SqlCommand cmd = new SqlCommand("", sqlct);
string sql = "select * from ininfo where MID= '" + comMID.Text.Trim() + " ' ";
cmd.CommandText = sql;
if (null == cmd.ExecuteScalar())
{
string sql1 = "insert into ininfo (MID,InAccount,InPrice,InValue,InDate,InDealer,InSaver,InStore,Re) values " + "('" + comMID.Text.Trim() + " ' , ' " +
textAccount.Text.Trim() + " '," + " ' " + textPrice.Text.Trim() + " ' , ' " + textValue.Text.Trim() + " ' , ' " + date1.Text.Trim() + " ' , ' " + textDealer.Text.Trim() + " ' , " + " ' " +
textSaver.Text.Trim() + " ' , ' " + textStore.Text.Trim() + " ' , ' " + textRe.Text.Trim() + "')";
cmd.CommandText = sql1;
cmd.ExecuteNonQuery();//列名 'InDate' 无效。
MessageBox.Show("添加入库信息成功!","提示");
this.Close();
}
else
{
MessageBox.Show("物资编号" + comMID.Text.Trim() +"已经存在!","警告");
sqlct.Close();
}
怎么会列名无效呢 是不是存储语句错呢?
求高手解决 实在是不解决不了了 谢谢啦 数据库中有这一列的 类型是:datetime 求高手 谢谢
textAccount.Text.Trim() + " '," + " ' " + textPrice.Text.Trim() + " ' , ' " + textValue.Text.Trim() + " ' , ' " + date1.Text.Trim() + " ' , ' " + textDealer.Text.Trim() + " ' , " + " ' " +
textSaver.Text.Trim() + " ' , ' " + textStore.Text.Trim() + " ' , ' " + textRe.Text.Trim() + "')";
cmd.CommandText = sql1;//看看构造的sql1是否正确
MessageBox.Show(sql1);然后将sql1复制到查询分析器运行看看结果
1,连错了数据库
2,表中没有该字段
3,sql语句里面没有该字段或者拼写错误