Dim objConn As SqlConnection
Dim objCmd As SqlCommand
Dim dtAdapter As New SqlDataAdapter
Dim strSQL As String
Sub Page_Load(ByVal sender As Object, ByVal e As EventArgs)
Dim strConnString As String
strConnString = "Server=localhost\SQLExpress;Database=Myweb;Trusted_Connection=True;"
objConn = New SqlConnection(strConnString)
objConn.Open()
If Not Page.IsPostBack() Then
BindData()
End If
End Sub
Sub BindData()
Dim dtadapter As SqlDataAdapter
Dim dt As New DataTable
strSQL = "SELECT * FROM Username"
dtadapter = New SqlDataAdapter(strSQL, objConn)
dtadapter.Fill(dt)
'dtadapter.Close()
dtadapter = Nothing
End Sub
Sub Page_UnLoad()
objConn.Close()
objConn = Nothing
End Sub
Sub modDeleteCommand(ByVal sender As Object, ByVal e As GridViewDeleteEventArgs)
strSQL = "DELETE FROM ACCESSORIES WHERE UserId = '" & GridView2.DataKeys.Item(e.RowIndex).Value & "'"
objCmd = New SqlCommand(strSQL, objConn)
objCmd.ExecuteNonQuery()
GridView2.EditIndex = -1
BindData()
End Sub
ERROR!!
System.Data.SqlClient.SqlException was unhandled by user code
Invalid column name 'UserId'. แต่คอลัมก้อมีนินา รบกวนด้วยค้า
Tag : .NET, VBScript, Web (ASP.NET), VB.NET, VS 2005 (.NET 2.x)