这是delete的源码:
Protected Sub MyDataGrid_Delete(source As Object, e As DataGridCommandEventArgs) dim ProductID as integer=MyDataGrid.Datakeys(e.Item.ItemIndex)
dim sqlStatement as string="delete products where productID=" & ProductID
dim myConnection as new sqlConnection("server=aspnet;database=northwind;uid=sa;pwd=admin123;")
dim myCommand as new sqlCommand(sqlStatement,myConnection) MyCommand.CommandTimeOut=15
Mycommand.CommandType=CommandType.text try
MyConnection.open()
MyCommand.ExecuteNonQuery()
MyConnection.Close()
catch ee as Exception
throw ee
end try MyDataGrid.EditItemIndex=-1
BindGrid()
End Sub
错误信息:
“/”应用程序中的服务器错误。
--------------------------------------------------------------------------------DELETE 语句与 COLUMN REFERENCE 约束 'FK_Order_Details_Products' 冲突。该冲突发生于数据库 'Northwind',表 'Order Details', column 'ProductID'。语句已终止。
说明: 执行当前 Web 请求期间,出现未处理的异常。请检查堆栈跟踪信息,以了解有关该错误以及代码中导致错误的出处的详细信息。 异常详细信息: System.Data.SqlClient.SqlException: DELETE 语句与 COLUMN REFERENCE 约束 'FK_Order_Details_Products' 冲突。该冲突发生于数据库 'Northwind',表 'Order Details', column 'ProductID'。语句已终止。
Protected Sub MyDataGrid_Delete(source As Object, e As DataGridCommandEventArgs) dim ProductID as integer=MyDataGrid.Datakeys(e.Item.ItemIndex)
dim sqlStatement as string="delete products where productID=" & ProductID
dim myConnection as new sqlConnection("server=aspnet;database=northwind;uid=sa;pwd=admin123;")
dim myCommand as new sqlCommand(sqlStatement,myConnection) MyCommand.CommandTimeOut=15
Mycommand.CommandType=CommandType.text try
MyConnection.open()
MyCommand.ExecuteNonQuery()
MyConnection.Close()
catch ee as Exception
throw ee
end try MyDataGrid.EditItemIndex=-1
BindGrid()
End Sub
错误信息:
“/”应用程序中的服务器错误。
--------------------------------------------------------------------------------DELETE 语句与 COLUMN REFERENCE 约束 'FK_Order_Details_Products' 冲突。该冲突发生于数据库 'Northwind',表 'Order Details', column 'ProductID'。语句已终止。
说明: 执行当前 Web 请求期间,出现未处理的异常。请检查堆栈跟踪信息,以了解有关该错误以及代码中导致错误的出处的详细信息。 异常详细信息: System.Data.SqlClient.SqlException: DELETE 语句与 COLUMN REFERENCE 约束 'FK_Order_Details_Products' 冲突。该冲突发生于数据库 'Northwind',表 'Order Details', column 'ProductID'。语句已终止。
注意:SQL中的语句语法
1.string:"Select * from .... where ProductName = '" + string + "'"
2.integer:"Select * from .... where ProductID = " + integerDelete的问题可能出自你的数据库的结构,你试图先删除关联的父表的记录,再删子表的!
只有让客户取消订购了。(先删除表OrderDetails中对应的记录)
delete的问题已经解决。
update还是不太明白应该怎么改。yohomonkey(关在笼子里的猴) 可否说得详细点
SQL:select * from ... where id = 11111 int type!
错写成:
select * from ... where id = ‘11111’ inttype…………》string!
结果出错了!
也就是把一个string的值例如“123”在sql中付给了Int的column,导致语句出错。
楼主也查查看,这种错误很容易出现的,因为大家往往相信系统会自动转换类型。
在一个sql中的string和int的写法有区别:
付值时最好string要用'',int是不用的。