方法1: Insert into
方法2: 与DataSet绑定然后操纵DataSet,最后Update

解决方案 »

  1.   

    using System.data.SqlClient;
    ...
    ..Sqlconnection conn = new SqlConnection("...connecting string...");
    string sqlIns = "Insert into .......";//Sql Statement
    SqlCommand  cmd = new SqlCommand(sqlIns,conn);
    Sqlcommand.ExecuteNonQuery();
    .....
      

  2.   

    你们估计还没明白我的意思,我已经把dataset中的表绑定到一个datagrid上了,这时我放一个按钮“插入”,就在datagrid中的当前位置插入一条空白记录,当然实际上是应该在表中进行操作的。而这个表是由SqlDataAdapter产生的,同时它也生成了sqlSelectCommand,sqlInsetCommand,sqlUpdateCommand!sqlInsertCommand的CommandText值已经给出,只是其中有很多参数,怎样把实际值当做参数传给sqlInsertCommand从而在表中生成新纪录???
      

  3.   

    OleDbDataAdapter catDA = new OleDbDataAdapter("SELECT CategoryID, CategoryName FROM Categories ORDER BY CategoryID", nwindConn);    catDA.InsertCommand = new OleDbCommand("INSERT INTO Categories (CategoryName) Values(?)", nwindConn);
        catDA.InsertCommand.CommandType = CommandType.Text;    catDA.InsertCommand.Parameters.Add("@CategoryName", OleDbType.Char, 15, "CategoryName");    nwindConn.Open();
     
        // Fill the DataSet.
        DataSet catDS = new DataSet();
        catDA.Fill(catDS, "Categories");    // Add a new row.
        DataRow newRow = catDS.Tables["Categories"].NewRow();
        newRow["CategoryName"] = "New Category";
        catDS.Tables["Categories"].Rows.Add(newRow);    // Include an event to fill in the Autonumber value.
        // Update the DataSet.
        catDA.Update(catDS, "Categories");    nwindConn.Close();
    不知对你是否有用?
      

  4.   

    不知你用过delphi 没有,在delphi里可以插入一条空白记录的,提交时才会检查约束,而在C#中怎样插入一条空白记录,这条空白记录显示在与表相连的dataGrid里?