W
wserfer
Unregistered / Unconfirmed
GUEST, unregistred user!
Sub MyDataGrid_Update(obj as object, e as DataGridCommandEventArgs)
Dim CurrItem As DataGridItem
CurrItem = MyDataGrid.Items(e.Item.Itemindex)
Dim NameTextBox As TextBox= CurrItem.FindControl("FixingName")
if NameTextBox.Text<>"" then
Dim StyleTextBox As TextBox = CurrItem.FindControl("FixingStyle")
Dim UnitTextBox As TextBox = CurrItem.FindControl("FixUnit")
Dim MemoTextBox As TextBox = CurrItem.FindControl("FixingMemo")
Dim strSQL as string="update fixing set FixingName='" &
NameTextBox.text &
_
"',FixingStyle='" &
StyleTextBox.Text &
"',FixingMemo='" &
MemoTextBox.Text &
"' where " &
_
"FixingFullID='"+MyDataGrid.DataKeys(CType(E.Item.ItemIndex, Integer))+"'"
' 上面的SQL字符串我也曾嚐試用存儲過程代替過,但仍不行.
Dim objCmd as New OleDbCommand(strSQL, MyConnection)
try
MyConnection.Open
objCmd.ExecuteNonQuery
MyConnection.Close
catch CurrErrors as Exception
throw CurrErrors
end try
MyDataGrid.EditItemIndex=-1
MyDataGrid.DataBind()
End if
End sub
當我要更新時,便會出現以下錯誤提示信息:
Exception Details: System.NullReferenceException: Object reference not set to an instance of an object
Dim CurrItem As DataGridItem
CurrItem = MyDataGrid.Items(e.Item.Itemindex)
Dim NameTextBox As TextBox= CurrItem.FindControl("FixingName")
if NameTextBox.Text<>"" then
Dim StyleTextBox As TextBox = CurrItem.FindControl("FixingStyle")
Dim UnitTextBox As TextBox = CurrItem.FindControl("FixUnit")
Dim MemoTextBox As TextBox = CurrItem.FindControl("FixingMemo")
Dim strSQL as string="update fixing set FixingName='" &
NameTextBox.text &
_
"',FixingStyle='" &
StyleTextBox.Text &
"',FixingMemo='" &
MemoTextBox.Text &
"' where " &
_
"FixingFullID='"+MyDataGrid.DataKeys(CType(E.Item.ItemIndex, Integer))+"'"
' 上面的SQL字符串我也曾嚐試用存儲過程代替過,但仍不行.
Dim objCmd as New OleDbCommand(strSQL, MyConnection)
try
MyConnection.Open
objCmd.ExecuteNonQuery
MyConnection.Close
catch CurrErrors as Exception
throw CurrErrors
end try
MyDataGrid.EditItemIndex=-1
MyDataGrid.DataBind()
End if
End sub
當我要更新時,便會出現以下錯誤提示信息:
Exception Details: System.NullReferenceException: Object reference not set to an instance of an object