求助:就是不知该怎么改了,提示未将对象引用设置到对象的实例。

xzp1030 2005-12-22 04:42:24
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实例化啊?
...全文
169 7 打赏 收藏 转发到动态 举报
写回复
用AI写文章
7 条回复
切换为时间正序
请发表友善的回复…
发表回复
xzp1030 2005-12-23
  • 打赏
  • 举报
回复
还是不对啊,//this.dataGrid1.SetDataBinding (ds,"goods");
这行本来我是没有注释掉的,后来我调试的时候才加的,不注释掉还是出同样的错误,
你说改成currencyManage ,也不行,都运行不起来.
继续等好心人帮忙
落伍者 2005-12-23
  • 打赏
  • 举报
回复
不好意思,前面说错了.
//this.dataGrid1.SetDataBinding (ds,"goods");
应该是这句话不能注释掉
xzp1030 2005-12-23
  • 打赏
  • 举报
回复
谢谢大家的帮忙,现在终于搞定了,结贴
落伍者 2005-12-22
  • 打赏
  • 举报
回复
private System.Windows.Forms.BindingManagerBase _Bind;
改为:
private System.Windows.Forms.CurrencyManager_Bind;
BindingManagerBase是一个抽象类
xzp1030 2005-12-22
  • 打赏
  • 举报
回复
好像就是没有实例化_Bind的缘故。
private System.Windows.Forms.BindingManagerBase _Bind;

_Bind = BindingContext[ds, "goods"];

这样是否对_Bind实例化了啊,要是不对的话,应该怎么做呢?
mark44404 2005-12-22
  • 打赏
  • 举报
回复
你好象没有绑定数据源到_Bind
Aallonlin 2005-12-22
  • 打赏
  • 举报
回复
[C#]
protected void BindControls()
{

text1.DataBindings.Add(new Binding
("Text", ds, "customers.custName"));
text2.DataBindings.Add(new Binding
("Text", ds, "customers.custID"));

DateTimePicker1.DataBindings.Add(new
Binding("Value", ds, "customers.CustToOrders.OrderDate"));

Binding b = new Binding
("Text", ds, "customers.custToOrders.OrderAmount");
b.Parse+=new ConvertEventHandler(CurrencyStringToDecimal);
b.Format+=new ConvertEventHandler(DecimalToCurrencyString);
text3.DataBindings.Add(b);

// Get the BindingManagerBase for the Customers table.
bmCustomers = this.BindingContext [ds, "Customers"];

/* Get the BindingManagerBase for the Orders table using the
RelationName. */
bmOrders = this.BindingContext[ds, "customers.CustToOrders"];

/* Bind the fourth TextBox control's Text property to the
third control's Text property. */
text4.DataBindings.Add("Text", text3, "Text");
}

msdn例子

110,536

社区成员

发帖
与我相关
我的任务
社区描述
.NET技术 C#
社区管理员
  • C#
  • Web++
  • by_封爱
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告

让您成为最强悍的C#开发者

试试用AI创作助手写篇文章吧