更新DataGrid數據時觸發的UPDATE事件(代碼見下)是否有錯??(100分)

  • 主题发起人 主题发起人 wserfer
  • 开始时间 开始时间
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='" &amp;
NameTextBox.text &amp;
_
"',FixingStyle='" &amp;
StyleTextBox.Text &amp;
"',FixingMemo='" &amp;
MemoTextBox.Text &amp;
"' where " &amp;
_
"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
 
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='" &amp;
NameTextBox.text &amp;
_
"',FixingStyle='" &amp;
StyleTextBox.Text &amp;
"',FixingMemo='" &amp;
MemoTextBox.Text &amp;
_
"' where FixingFullID='" &amp;
MyDataGrid.DataKeys(CType(E.Item.ItemIndex, Integer)) &amp;
"'"
' 上面的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
改为
Dim CurrItem As new DataGridItem
试试,以前我遇到这样的问题就是在定义变量时没有是用new,错误和你差不多
 
后退
顶部