SqlCommandBuilder

  • Thread starter Thread starter Magnus
  • Start date Start date
M

Magnus

Hi

I have a DataGrid that represents an whole databasetable. I fill the
grid with a DataSet, see below.

I wonder if it is possible to turn off the possibility to run Insert
commands for SqlCommandBuilder object when the GetUpdateCommand() is
run?

I dont want the user to be able to add rows in the table with the
SqlCommandBuilder



public DataSet fillDataSet()
{
DataSet returnSet = new DataSet();

string commandString = "select * from PriceList";
priceAdapter = new SqlDataAdapter(commandString, sqlConnection1);

priceAdapter.Fill(returnSet, "PriceList");

return returnSet;

}

public void updatePriceList(DataSet newPriceList)
{
sqlCommandBuilder.DataAdapter = priceAdapter;
priceAdapter.SelectCommand = new SqlCommand("select * from
PriceList");

priceAdapter.SelectCommand.Connection = sqlConnection1;

SqlCommand test = sqlCommandBuilder.GetUpdateCommand();
priceAdapter.UpdateCommand = test;

priceAdapter.Update(newPriceList.Tables["PriceList"]);

}

thanks,

Magnus
 
Magnus, I don't think that will work but I'm not positive. But you can stop
it in the UI. If you are using a binding context, don't use AddNew
anywhere. If you are using a DataGrid, bind it to a DataView and set the
AllowNew Property to false. I'll see if I can find anything about shutting
off the Insert command.
 
Back
Top