窗体上有datagrid 和textbox,想给datagrid新增加一行,通过textbox的change事件,改变datagrid带*那行相应的列。

解决方案 »

  1.   

    datagrid和textbox绑定到同一数据源就行!
      

  2.   

    用一个“添加”按钮的CLICK事件可以吗?
    string strFirst =this.firstNameText.Text.Trim();
    string strLast =this.lastNameText.Text.Trim();

    string sendValues = "('"+ intMaxNumberID +"','"+ strFirst +"','"+ strLast +"')";
    sendSQL = "insert into studentInfo (StudentID,FirstName,LastName)  values " + sendValues;
    this.link.UpdateDataBase(sendSQL);
                MessageBox.Show("插入记录成功!","提示");

    string tempStrSQL = "select * from " + sendTableName;
    this.link.SelectDataBase(sendDsPath,tempStrSQL,sendTableName);
      

  3.   

    public int UpdateDataBase(string tempStrSQL)
    {
    this.myConnection = new OleDbConnection(connectionString);
    //使用Command之前一定要先打开连接,后关闭连接,而DataAdapter则会自动打开关闭连接
    myConnection.Open();
    OleDbCommand tempSqlCommand = new OleDbCommand(tempStrSQL,this.myConnection);
    int intNumber = tempSqlCommand.ExecuteNonQuery();//返回数据库中影响的行数
    myConnection.Close();
    return intNumber;
    }
    public DataSet SelectDataBase(string dataSourcePath,string tempStrSQL,string tempTableName )

    this.strSQL = tempStrSQL;
    connectionString += "Data Source =" + dataSourcePath + ";";
    this.myConnection = new OleDbConnection(connectionString);
    this.da = new OleDbDataAdapter(this.strSQL,this.myConnection);
    this.ds.Clear();
    this.da.Fill(ds,tempTableName);
    return ds;//返回填充了数据的DataSet,其中数据表以tempTableName给出的字符串命名
    }