Updating a tableadapter.

In VS2005, when using the update method of the table adapter using a stored procedure, I can use the SourceColumn property of the parameters collection to map the TableAdapter columns to the parameters in the stored procedure.

However, I would like to be able to explicitly specify the values of one of the sprocs parameters i.e. not take it from a column. MSDN suggests that there is a value property that I can assign, but I can find it.

Thanks,

David McKinney.



Answer this question

Updating a tableadapter.

  • gotcf.net

    Hi!

    TableAdapter have UpdateCommand, DeleteCommand, etc. Each command can use Parameters collection. You need to add parameter there.



  • Seraph_78

    Hi,

    Try this code:

    SqlDataAdapter catDA = new SqlDataAdapter("SELECT CategoryID, CategoryName FROM Categories", nwindConn);

    //Usin Stored procedure
    catDA.UpdateCommand =
    new SqlCommand("sp_UpdateCategories , nwindConn);

    //Using Client side update statement
    catDA.UpdateCommand =
    new SqlCommand("UPDATE Categories SET CategoryName = @CategoryName " +
    "WHERE CategoryID = @CategoryID" , nwindConn);

    catDA.UpdateCommand.Parameters.Add("@CategoryName", SqlDbType.NVarChar, 15, "CategoryName");

    SqlParameter workParm = catDA.UpdateCommand.Parameters.Add("@CategoryID", SqlDbType.Int);
    workParm.SourceColumn = "CategoryID";
    workParm.SourceVersion = DataRowVersion.Original;

    DataSet catDS = new DataSet();
    catDA.Fill(catDS, "Categories");

    DataRow cRow = catDS.Tables["Categories"].Rows[0];
    cRow["CategoryName"] = "Your New Category here or textCategoryName.Text";

    catDA.Update(catDS);

    HTH,

    Michael Castillones



  • Updating a tableadapter.