求助:就是不知该怎么改了,提示未将对象引用设置到对象的实例。
using System;
using System.Drawing;
using System.Collections;
using System.ComponentModel;
using System.Windows.Forms;
using System.Data;
using System.Data.OleDb;
namespace 电算调货记录
{
/// <summary>
/// Form1 的摘要说明。
/// </summary>
public class Form1 : System.Windows.Forms.Form
{
private System.Windows.Forms.Label label1;
private System.Windows.Forms.Label label2;
private System.Windows.Forms.DataGrid dataGrid1;
private System.Windows.Forms.Label label3;
private System.Windows.Forms.Label label4;
private System.Windows.Forms.TextBox textBox4;
private System.Windows.Forms.Label label5;
private System.Windows.Forms.BindingManagerBase _Bind;
private System.Windows.Forms.TextBox txtdep;
private System.Windows.Forms.TextBox txtname;
private System.Windows.Forms.TextBox txtcount;
private System.Windows.Forms.TextBox txtdec;
private System.Windows.Forms.DateTimePicker dtpdate;
private System.Windows.Forms.Button btadd;
private System.Windows.Forms.Button btchange;
private System.Windows.Forms.Button btdelete;
private System.Windows.Forms.Button btprev;
private System.Windows.Forms.Button btnext;
private OleDbCommandBuilder ole_cb;//用于自动生成SQL指令
/// <summary>
/// 必需的设计器变量。
/// </summary>
private System.ComponentModel.Container components = null;
public Form1()
{
//
// Windows 窗体设计器支持所必需的
//
InitializeComponent();
//
// TODO: 在 InitializeComponent 调用后添加任何构造函数代码
//
}
/// <summary>
/// 清理所有正在使用的资源。
/// </summary>
protected override void Dispose( bool disposing )
{
if( disposing )
{
if (components != null)
{
components.Dispose();
}
}
base.Dispose( disposing );
}
+窗体设计器生成的代码
/// <summary>
/// 应用程序的主入口点。
/// </summary>
[STAThread]
static void Main()
{
Application.Run(new Form1());
}
private void Form1_Load(object sender, System.EventArgs e)
{
string strCon = "Provider=sqloledb;Data Source=good;Initial Catalog=df;User ID=sa;Password=diansuan;";
//System.Data.OleDb.OleDbCommand myCommand;
OleDbConnection strConn = new OleDbConnection(strCon);
strConn.Open();
string vSelect = "select * from goods";
OleDbDataAdapter myAdapter = new OleDbDataAdapter(vSelect,strConn);
ole_cb = new OleDbCommandBuilder(myAdapter);
DataSet ds = new DataSet();
myAdapter.Fill(ds,"goods");
//this.dataGrid1.SetDataBinding (ds,"goods");
_Bind = BindingContext[ds, "goods"];
txtdep.DataBindings.Add ("Text",ds,"goods.depart");
txtname.DataBindings.Add("Text",ds,"goods.name");
txtcount.DataBindings.Add("Text",ds,"goods.count");
dtpdate.DataBindings.Add("",ds,"goods.cdate");
txtdec.DataBindings.Add("Text",ds,"goods.remark");
}
private void btprev_Click(object sender, System.EventArgs e)
{
if(_Bind.Position == 0 )
MessageBox.Show("已经到了第一条记录!","信息提示",MessageBoxButtons.OK,MessageBoxIcon.Information);
else
_Bind.Position -=1;
}
private void btnext_Click(object sender, System.EventArgs e)
{
if(_Bind.Position == _Bind.Count -1)
MessageBox.Show("已经到了最后一条记录!","信息提示",MessageBoxButtons.OK ,MessageBoxIcon.Information );
else
_Bind.Position +=1;
}
}
}当点击下一条的时候,就提示错误,怎么把这个_Bind实例化啊?