Imports System.Data.SqlClient
Dim constr As String = "Data Source=.\SQLEXPRESS;AttachDbFilename=|DataDirectory|\ASPNETDB.MDF;Integrated Security=True;User Instance=True"
Protected Sub GridView1_RowUpdated(ByVal sender As Object, ByVal e As System.Web.UI.WebControls.GridViewUpdatedEventArgs) Handles GridView1.RowUpdated
For Each myRow As GridViewRow In GridView1.Rows
'Find the checkbox
Dim lab1 As Label = DirectCast(myRow.FindControl("Label1"), Label)
Dim lab4 As Label = DirectCast(myRow.FindControl("Label4"), Label)
Try
Using conn = New SqlConnection(constr)
Using cmd = conn.CreateCommand()
conn.Open()
Dim sql As String = "UPDATE a1_volvo SET travel = @travel WHERE travelid = @travelid"
cmd.CommandText = sql
cmd.Parameters.AddWithValue("@travel", lab4.Text)
cmd.Parameters.AddWithValue("@travelid", lab1.Text)
cmd.ExecuteNonQuery()
End Using
End Using
Catch ex As Exception
Response.Write(ex.Message)
End Try
Next
End Sub
ERROR:對象引用未設置爲對象的實例..GridView的這個更新命令有什麼問題?
不要喊 - 關掉大寫鎖 – 2011-03-11 07:05:03