I am using the following code in a button to delete a row from my gridview:
int i = GridView1.SelectedIndex;
tshirtSet.Tables["tshirts"].Rows[i].Delete();
GridView1.DataSource = tshirtset;
GridView1.DataBind();
localhost.Service mc = new localhost.Service();
mc.GetTshirtSet();
mc.ModifyDatabase(tshirtSet); <-------(Error on this line)
The gridview is being used by a web service which is linked to the database, this method is used to retrieve data from my database
[WebMethod]
public DataSet GetTshirtSet()
{
DataSet tshirtSet = new DataSet();
string database = "Provider=Microsoft.ACE.OLEDB.12.0;Data Source=|DataDirectory|/shop.accdb;Persist Security Info=True";
OleDbConnection myConn = new OleDbConnection(database);
string queryStr = "SELECT * FROM tshirt";
OleDbDataAdapter myDataAdapter = new OleDbDataAdapter(queryStr, myConn);
myConn.Open();
myDataAdapter.Fill(tshirtSet, "Tshirt");
myConn.Close();
return tshirtSet;
}
This method is also in the webservice, this basically updates the database:
[WebMethod]
public string ModifyDatabase(DataSet myDataset)
{
string database = "Provider=Microsoft.ACE.OLEDB.12.0;Data Source=|DataDirectory|/shop.accdb;Persist Security Info=True";
OleDbConnection myConn = new OleDbConnection(database);
OleDbDataAdapter myDataAdapter = new OleDbDataAdapter("Select * from tshirt", myConn);
OleDbCommandBuilder builder = new OleDbCommandBuilder(myDataAdapter);
builder.QuotePrefix = "[";
builder.QuoteSuffix = "]";
myConn.Open();
myDataAdapter.Update(myDataset, "tshirt");
myConn.Close();
return "done";
}
These are the methods, I cant seem to delete a row, any suggestions?
System.Web.Services.Protocols.SoapException: Server was unable to process request. ---> System.InvalidOperationException: Dynamic SQL generation for the DeleteCommand is not supported against a SelectCommand that does not return any key column information. at System.Data.Common.DbDataAdapter.UpdatingRowStatusErrors(RowUpdatingEventArgs rowUpdatedEvent, DataRow dataRow) at System.Data.Common.DbDataAdapter.Update(DataRow[] dataRows, DataTableMapping tableMapping) at System.Data.Common.DbDataAdapter.UpdateFromDataTable(DataTable dataTable, DataTableMapping tableMapping) at System.Data.Common.DbDataAdapter.Update(DataSet dataSet, String srcTable) at Service.ModifyDatabase(DataSet myDataset) in e:\web\App_Code\Service.cs:line 183 --- End of inner exception stack trace ---