DataRow newRow=dataTable.NewRow();
newRow["CustomerID"]=txtCustomerID.Text;
newRow["Country"]=txtCountry.Text;
...
dataTable.Rows.Add(newRow);
DataAdapter.Update(myDataSet,"Customers");
Application.DoEvents();
myDataSet.AcceptChanges();

解决方案 »

  1.   

    老兄,我是在我在DataGrid里选的记录之前查入记录,不是查在之前
      

  2.   

    DataRow row = this.cmDataSet.Tables["CommiteeMan"].NewRow();
    int newrowIndex= this.dataGrid.CurrentRowIndex+1;
    row["编号"]=this.dataGrid.CurrentRowIndex+1;
    this.listBox.SelectedIndex=
    this.dataGrid.CurrentRowIndex+1;
    this.cmDataSet.Tables["CommiteeMan"].Rows.InsertAt(row,newrowIndex);
    这样也不行,请各位帮忙
      

  3.   

    用SQL语句;insert into tableName values (...)就能搞定
      

  4.   

    row["编号"]=this.dataGrid.CurrentRowIndex+1;
    应该是row["编号']这个地方不对
      

  5.   

    具体情况如下:
    Winform上面是邦定数据库的textbox,下面是一个datagrid也是邦定的,然后我的想法是在下面的Datagrid中选取的行(记录)前或后插入记录,
    编号是主键,然后其他数据通过上面帮定的textbox输入
    如下是我的代码,思路估计也是错的,望大家指教:
    this.cmDataSet.EnforceConstraints=false;
    DataRow row = this.cmDataSet.Tables["CommiteeMan"].NewRow();
    int newrowIndex= this.dataGrid.CurrentRowIndex+1;
    row["编号"]=this.dataGrid.CurrentRowIndex+1;

    this.cmDataSet.Tables["CommiteeMan"].Rows.InsertAt(row,newrowIndex);
    this.dataGrid.CurrentRowIndex++;
    this.cmDataSet.EnforceConstraints=true;
      

  6.   

    调换以下两句的顺序即可
    DataRow row = this.cmDataSet.Tables["CommiteeMan"].NewRow();
    int newrowIndex= this.dataGrid.CurrentRowIndex;正确顺序为:
    int newrowIndex= this.dataGrid.CurrentRowIndex;
    DataRow row = this.cmDataSet.Tables["CommiteeMan"].NewRow();