我在按钮中使用以下代码从我的 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)
链接到数据库的 Web 服务正在使用 gridview,此方法用于从我的数据库中检索数据
[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;
}
这个方法也在webservice中,这基本更新了数据库:
[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";
}
这些是方法,我似乎无法删除一行,有什么建议吗?
System.Web.Services.Protocols.SoapException:服务器无法处理请求。---> System.InvalidOperationException:对于不返回任何键列信息的 SelectCommand,不支持为 DeleteCommand 生成动态 SQL。在 System.Data.Common.DbDataAdapter.UpdatingRowStatusErrors(RowUpdatingEventArgs rowUpdatedEvent, DataRow dataRow) 在 System.Data.Common.DbDataAdapter.Update(DataRow[] dataRows, DataTableMapping tableMapping) 在 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 --- 内部异常堆栈结束痕迹 - -