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  求高手  谢谢 

解决方案 »

  1.   

    cmd.CommandText = sql1;在这里下断点。看 sql1 是什么。拼写、引号。
      

  2.   

    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;//看看构造的sql1是否正确
    MessageBox.Show(sql1);然后将sql1复制到查询分析器运行看看结果
      

  3.   

    ininfo表中不存在InDate字段检查一下看看是不是表里的这个字段有问题
      

  4.   

    你把这个语句在SQL中执行下,看有没错误。
      

  5.   

    列名无效的问题:
    1,连错了数据库
    2,表中没有该字段
    3,sql语句里面没有该字段或者拼写错误