textBox绑定数据源后,改变BindingManageBase的position值,但textBox的值未变,请各位帮忙,代码如下:
private SqlConnection con;
private SqlCommand comm;
private SqlDataAdapter dataAdapter;
private DataSet ds_ObjectInfo; private BindingManagerBase bm;
private void Form1_Load(object sender, System.EventArgs e)
{
string connstr="user id=sa;password=123;initial catalog=try;data source=JS08;";
con=new SqlConnection(connstr);
comm=new SqlCommand();
comm.Connection=con;
comm.CommandType=CommandType.StoredProcedure;
comm.CommandText="usp_AllObjectsInfo";
dataAdapter=new SqlDataAdapter(comm);
ds_ObjectInfo=new DataSet();
dataAdapter.Fill(ds_ObjectInfo,"ObjectInfo"); bm=this.BindingContext[ds_ObjectInfo,"ObjectInfo"];
textBox_Name.DataBindings.Add("Text",ds_ObjectInfo.Tables["ObjectInfo"],"ObjectName");
textBox_Religion.DataBindings.Add("Text",ds_ObjectInfo.Tables["ObjectInfo"],"Religion");
} private void button1_Click(object sender, System.EventArgs e)
{
bm.Position=3;
this.BindingContext[ds_ObjectInfo,"ObjectInfo"].Position=3;
}
private SqlConnection con;
private SqlCommand comm;
private SqlDataAdapter dataAdapter;
private DataSet ds_ObjectInfo; private BindingManagerBase bm;
private void Form1_Load(object sender, System.EventArgs e)
{
string connstr="user id=sa;password=123;initial catalog=try;data source=JS08;";
con=new SqlConnection(connstr);
comm=new SqlCommand();
comm.Connection=con;
comm.CommandType=CommandType.StoredProcedure;
comm.CommandText="usp_AllObjectsInfo";
dataAdapter=new SqlDataAdapter(comm);
ds_ObjectInfo=new DataSet();
dataAdapter.Fill(ds_ObjectInfo,"ObjectInfo"); bm=this.BindingContext[ds_ObjectInfo,"ObjectInfo"];
textBox_Name.DataBindings.Add("Text",ds_ObjectInfo.Tables["ObjectInfo"],"ObjectName");
textBox_Religion.DataBindings.Add("Text",ds_ObjectInfo.Tables["ObjectInfo"],"Religion");
} private void button1_Click(object sender, System.EventArgs e)
{
bm.Position=3;
this.BindingContext[ds_ObjectInfo,"ObjectInfo"].Position=3;
}
解决方案 »
- 关于继承添加事件的问题???
- form窗口调用页面消除掉页面背景,显示为透明的问题?
- 询问:(Winform)关于在vs2005下使用WebBrowser控件加载flash的问题
- 想把TXT中的数据参入数据库,想这样用什么拆开
- C#中的变量如何跨表单引用
- 请教:如何使用MDI窗体做一个多窗口浏览器???
- 刚刚要建Crystal表的时候才发现没有安装进来。。。求推荐下载地址(急)
- 数据显示问题
- 怎样实现窗口最小化时,窗口隐藏到托盘图标上?
- dataGrid连接数据库的问题
- 如何快速判断一个DataSet(只有一个DataTable)中是否已经存在某个字段?
- ArrayList如何改变某一项的值?
textBox_Name.DataBindings.Add("Text",ds_ObjectInfo.Tables["ObjectInfo"],"ObjectName
最好用
textbox.text="";
bm=this.BindingContext[ds_ObjectInfo,"ObjectInfo"];
bm.Position=3;都注释掉试试..
textBox_Name.DataBindings.Add("Text",ds_ObjectInfo,"ObjectInfo.ObjectName");
textBox_Religion.DataBindings.Add("Text",ds_ObjectInfo,"ObjectInfo.Religion");
谢谢!
问题解决,错在这种不起眼的地方,浪费了我一天的时间,真是郁闷啊!