在数据捆绑时,遇到问题,当下一条记录按纽浏览全部记录后,返回第一条记录,再按下一条记录,则不能变化.
代码如下:
string strSQL="select pro_id as 产品编号,pro_kind as 产品类型,pro_name as 产品名称,pro_price as 产品价格,pro_count as 产品总量,pro_out as 出货量,pro_date as 进货日期,pro_company,pro_comm,imgdata from productInfo";
string strConn = "server=ANDY;uid=sa;pwd=;database=PMS";
SqlConnection myCn=new SqlConnection(strConn);
SqlDataAdapter myAdatper=new SqlDataAdapter(strSQL,myCn);

myAdatper.Fill(myDs,"productinfo");
dataGrid1.DataSource=myDs.Tables["productinfo"].DefaultView;
this.txtCompany.DataBindings.Add("Text",myDs.Table[0],"pro_company");
this.txtComment.DataBindings.Add("Text",myDs.Tables[0],"pro_comm");
private void bnPrev_Click(object sender, System.EventArgs e)
{
this.dataGrid1.UnSelect(this.dataGrid1.CurrentRowIndex);
if(this.dataGrid1.CurrentRowIndex >0)
this.dataGrid1.CurrentRowIndex --;
this.dataGrid1.Select(this.dataGrid1.CurrentRowIndex);
//this.txtCompany.DataBindings.Add("Text",mydata.Tables[0],"pro_company");
} private void bnNext_Click(object sender, System.EventArgs e)
{
this.dataGrid1.CurrentRowIndex = this.BindingContext[myDs.Tables["productinfo"]].Position;
this.dataGrid1.UnSelect(this.dataGrid1.CurrentRowIndex);
this.BindingContext[myDs.Tables["productinfo"]].Position++;
this.dataGrid1.CurrentRowIndex = this.BindingContext[myDs.Tables["productinfo"]].Position;
this.dataGrid1.Select(this.dataGrid1.CurrentRowIndex);
}问题出在哪里.
如果我直接拉组件的话是可以的

解决方案 »

  1.   

    如果这部分代码:
    string strSQL="select pro_id as 产品编号,pro_kind as 产品类型,pro_name as 产品名称,pro_price as 产品价格,pro_count as 产品总量,pro_out as 出货量,pro_date as 进货日期,pro_company,pro_comm,imgdata from productInfo";
    string strConn = "server=ANDY;uid=sa;pwd=;database=PMS";
    SqlConnection myCn=new SqlConnection(strConn);
    SqlDataAdapter myAdatper=new SqlDataAdapter(strSQL,myCn);

    myAdatper.Fill(myDs,"productinfo");
    直接拉组件的话,这个捆绑技术是可以实现的