Imports System.Data
Imports System.Data.SqlClient
Partial Class Purchase_Default
Inherits System.Web.UI.Page
Dim objConn As SqlConnection
Dim objCmd As SqlCommand
Dim strSQL As String
Dim CusID As String = ""
End Sub
Protected Sub gvManageBindData()
strSQL = "SELECT * FROM CUS"
Dim dtReader As SqlDataReader
objCmd = New SqlCommand(strSQL, objConn)
dtReader = objCmd.ExecuteReader()
gvManage.DataSource = dtReader
gvManage.DataBind()
dtReader.Close()
dtReader = Nothing
End Sub
Protected Sub dvEditBindData()
strSQL = "SELECT * FROM Cus where CUSID = '" & CUSID & "' "
Dim dtReader As SqlDataReader
objCmd = New SqlCommand(strSQL, objConn)
dtReader = objCmd.ExecuteReader()
dvEdit.DataSource = dtReader
dvEdit.DataBind()
dtReader.Close()
dtReader = Nothing
End Sub
Protected Sub Page_UnLoad()
objConn.Close()
objConn = Nothing
End Sub
End Class
The DELETE statement conflicted with the REFERENCE constraint "FK_PurchaseDetail_Book". The conflict occurred in database "Bookshop", table "dbo.PurchaseDetail", column 'BookID'.
Protected Sub gvManage_RowDeleting(ByVal sender As Object, ByVal e As System.Web.UI.WebControls.GridViewDeleteEventArgs) Handles gvManage.RowDeleting
strSQL = "DELETE FROM Book WHERE BookID = '" & gvManage.DataKeys.Item(e.RowIndex).Value & "'"
objCmd = New SqlCommand(strSQL, objConn)
objCmd.ExecuteNonQuery()
gvManageBindData()
End Sub