求帮助,这个怎么老是出现未将对象引用设置到对象的实例,但是不报错啊。。。

using System;c#新手求助——————
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
using System.Data.SqlClient;

namespace 仓库管理系统
{
public partial class 订单表添加 : Form
{
private SqlDataAdapter objsqldataadapter;
private SqlConnection objsqlconn;
private DataSet objdataset;
private SqlParameter objsqlparameter;
public 订单表添加()
{
InitializeComponent();
}

    private bool ValidateFields() 
    {
        bool returnValue = true;
        if (textBox1.Text == "")
        {
            MessageBox.Show("编号不能为空,请输入", "提示");
            textBox1.Focus();
            return false;
        }
        else
        {
            for (int i = 0; i < this.textBox1.Text.Length; i++)
            {
                if (!char.IsNumber(textBox1.Text.ToString(), i))
                {
                    MessageBox.Show("编号为数字谢谢!!!!!", "提示");
                    this.textBox1.Focus();
                    return false;
                }
            }
            for (int i = 0; i < this.textBox2.Text.Length; i++)
            {
                if (!char.IsNumber(textBox2.Text.ToString(), i))
                {
                    MessageBox.Show("货物代号应为数字!", "提示");
                    this.textBox2.Focus();
                    return false;
                }
            }
            for (int i = 0; i < this.textBox6.Text.Length; i++)
            {
                if (!char.IsNumber(textBox6.Text.ToString(), i))
                {
                    MessageBox.Show("进货时间应为数字!", "提示");
                    this.textBox6.Focus();
                    return false;
                }
            }
            for (int i = 0; i < this.textBox8.Text.Length; i++)
            {
                if (!char.IsNumber(textBox8.Text.ToString(), i))
                {
                    MessageBox.Show("价格应为数字!", "提示");
                    this.textBox8.Focus();
                    return false;
                }
            }
            for (int i = 0; i < this.textBox3.Text.Length; i++)
            {
                if (char.IsNumber(textBox3.Text.ToString(), i))
                {
                    MessageBox.Show("付款与否应为汉子!", "提示");
                    this.textBox3.Focus();
                    return false;
                }
            }
            for (int i = 0; i < this.textBox4.Text.Length; i++)
            {
                if (!char.IsNumber(textBox4.Text.ToString(), i))
                {
                    MessageBox.Show("数量应为数字!", "提示");
                    this.textBox4.Focus();
                    return false;
                }
            }
            for (int i = 0; i < this.textBox5.Text.Length; i++)
            {
                if (!Char.IsNumber(textBox5.Text.ToString(), i))
                {
                    MessageBox.Show("进货人应为数字!", "提示");
                    this.textBox5.Focus();
                    return false;
                }
            }
            for (int i = 0; i < this.textBox7.Text.Length; i++)
            {
                if (!char.IsNumber(textBox7.Text.ToString(), i))
                {
                    MessageBox.Show("入库时间应为数字!", "提示");
                    this.textBox7.Focus();
                    return false;
                }
            }
            return returnValue;
        }
    }
    private void 订单表添加_Load(object sender, EventArgs e)
    {
        objsqlconn = new SqlConnection("Data Source=DESKTOP-EVHJF9I;Initial Catalog=仓库管理系统;Integrated Security=True");
        objsqlconn.Open();
        objsqldataadapter = new SqlDataAdapter();
        objsqldataadapter.SelectCommand = new SqlCommand("select*from订货信息表", objsqlconn);
        objdataset = new DataSet();
        objsqldataadapter.Fill(objdataset, "订货单表");
        string insCmd = "insert into 订货单表 values(@编号,@货物代号,@进货时间,@价格,@付款与否,@数量,@进货人,@入库)";
        this .objsqldataadapter.InsertCommand = new SqlCommand (insCmd ,this.objsqlconn);
        objsqlparameter = objsqldataadapter.InsertCommand.Parameters.Add(new SqlParameter("@货物代号", System.Data.SqlDbType.Int));
        objsqlparameter.SourceColumn = "货物代号";
        objsqlparameter.SourceVersion = DataRowVersion.Current;
        objsqlparameter = objsqldataadapter.InsertCommand.Parameters.Add(new SqlParameter("@编号", System.Data.SqlDbType.Int));
        objsqlparameter.SourceColumn = "编号";
        objsqlparameter.SourceVersion = DataRowVersion.Current;
        objsqlparameter = objsqldataadapter.InsertCommand.Parameters.Add(new SqlParameter("@入库时间", System.Data.SqlDbType.Char,50));
        objsqlparameter.SourceColumn = "入库时间";
        objsqlparameter.SourceVersion = DataRowVersion.Current;
        objsqlparameter = objsqldataadapter.InsertCommand.Parameters.Add(new SqlParameter("@进货时间", System.Data.SqlDbType.Char,20));
        objsqlparameter.SourceColumn = "进货时间";
        objsqlparameter.SourceVersion = DataRowVersion.Current;
        objsqlparameter = objsqldataadapter.InsertCommand.Parameters.Add(new SqlParameter("@数量", System.Data.SqlDbType.Char, 50));
        objsqlparameter.SourceColumn = "数量";
        objsqlparameter.SourceVersion = DataRowVersion.Current;
        objsqlparameter = objsqldataadapter.InsertCommand.Parameters.Add(new SqlParameter("@进货人", System.Data.SqlDbType.Char,20));
        objsqlparameter.SourceColumn = "进货人";
        objsqlparameter.SourceVersion = DataRowVersion.Current;
        objsqlparameter = objsqldataadapter.InsertCommand.Parameters.Add(new SqlParameter("@付款与否", System.Data.SqlDbType.Char,20));
        objsqlparameter.SourceColumn = "付款与否";
        objsqlparameter.SourceVersion = DataRowVersion.Current;
        objsqlparameter = objsqldataadapter.InsertCommand.Parameters.Add(new SqlParameter("@价格", System.Data.SqlDbType.Char, 10));
        objsqlparameter.SourceColumn = "价格";
        objsqlparameter.SourceVersion = DataRowVersion.Current;
    }

    private void button1_Click(object sender, EventArgs e)
    {
        try
        {
            if (this.textBox1.Text != string.Empty && this.textBox2.Text != string.Empty && this.textBox6.Text != string.Empty && this.textBox4.Text != string.Empty && this.textBox5.Text != string.Empty && this.textBox3.Text != string.Empty && this.textBox8.Text != string.Empty && this.textBox7.Text != string.Empty)
            {
                if (ValidateFields ())
                {
                    DataRow row =objdataset.Tables["订货信息表"].NewRow();
                    row["编号"] = this.textBox1.Text;
                    row["货物代号"] = this.textBox2.Text;
                    row["入库时间"] = this.textBox7.Text;
                    row["价格"] = this.textBox8.Text;
                    row["付款与否"] = this.textBox3.Text;
                    row["数量"] = this.textBox4.Text;
                    row["进货人"] = this.textBox5.Text;
                    row["进货时间"] = this.textBox6.Text;
                    objdataset.Tables["订货信息表"].Rows.Add(row);
                    objdataset.HasChanges(DataRowState .Added);
                    objsqldataadapter.Update(objdataset,"订货信息表");
                    MessageBox.Show("添加成功","提示");
                    this.textBox1.Clear();
                    this.textBox2.Clear();
                    this.textBox3.Clear();
                    this.textBox8.Clear();
                    this.textBox5.Clear();
                    this.textBox6.Clear();
                    this.textBox7.Clear();
                    this.textBox4.Clear();
                    this.textBox1.Focus();
                }
            }
        else 
            MessageBox.Show ("提供完整信息!");
        }
        catch (SqlException ex)
        {
            MessageBox.Show(ex.Message.ToString());
        }
        catch (Exception genEX)
        {
            MessageBox.Show(genEX.Message.ToString());
        }
    }

    private void button2_Click(object sender, EventArgs e)
    {
        this.Close();
    }

}

}

相关文章:

  • 2021-12-12
  • 2021-11-10
  • 2021-11-06
  • 2022-01-18
  • 2021-06-06
  • 2021-11-07
  • 2021-12-11
  • 2021-09-20
猜你喜欢
  • 2022-01-05
  • 2021-10-09
  • 2022-01-16
  • 2021-04-16
  • 2021-08-10
  • 2021-08-30
  • 2021-12-02
相关资源
相似解决方案