#12002/12/23 16:15:29
1. 用DataGrid中显示记录,然后用EDIT--UPDATE进行更新;
2. debug也没有检查出错误,总之一切正常;
3. 就是EDIT时不能更新数据,其间try…catch 语名中的还显示:更新成功,可看看数据库中还是一样的没有更新,真的不知道怎么回事。
请版主帮我看看有什么问题……
请看原码:(VB)
sub dataGrid1_update(obj as object,e as DataGridCommandEventargs)
dim cols() as string = {"Name","Fwage","WorkDay","WorkHour" , _
"AddDay","AddHour","RestDay","RestHour","foreMoney","EatsMoney" , _
"PowerMoney","charterMoney","others"}
dim I as integer
dim strstate as string
dim params(12) as string
dim Updatecmd as string
for I = 0 to 12
dim currentTextbox as textBox
currentTextbox = e.item.findControl("edit_" & cols(I))
dim colvalue as string = currentTextbox.text
params(I) = colvalue
next
UpdateCmd = "update wage set Name=@Name,Fwage=@Fwage, " _
& " WorkDay=@WorkDay,WorkHour=@WorkHour,AddDay=@AddDay,AddHour=@AddHour, " _
& " RestDay=@RestDay,RestHour=@RestHour,foreMoney=@foreMoney,EatsMoney=@EatsMoney, " _
& " PowerMoney=@PowerMoney,charterMoney=@charterMoney,others=@others where ID=@id "
dim Dbcommand as oledbCommand
Dbcommand = new oledbCommand(UpdateCmd , Dbconn)
Dim objParam as oledbParameter
objParam = new oledbParameter("@Name",oledbType.char)
objParam.value = params(0)
Dbcommand.parameters.add(objParam)
objParam = new oledbParameter("@Fwage",oledbType.double)
objParam.value = params(1)
Dbcommand.parameters.add(objParam)
objParam = new oledbParameter("@WorkDay",oledbType.double)
objParam.value = params(2)
Dbcommand.parameters.add(objParam)
objParam = new oledbParameter("@WorkHour",oledbType.double)
objParam.value = params(3)
Dbcommand.parameters.add(objParam)
objParam = new oledbParameter("@AddDay",oledbType.double)
objParam.value = params(4)
Dbcommand.parameters.add(objParam)
objParam = new oledbParameter("@AddHour",oledbType.double)
objParam.value = params(5)
Dbcommand.parameters.add(objParam)
objParam = new oledbParameter("@RestDay",oledbType.double)
objParam.value = params(6)
Dbcommand.parameters.add(objParam)
objParam = new oledbParameter("@RestHour",oledbType.double)
objParam.value = params(7)
Dbcommand.parameters.add(objParam)
objParam = new oledbParameter("@foreMoney",oledbType.double)
objParam.value = params(8)
Dbcommand.parameters.add(objParam)
objParam = new oledbParameter("@EatsMoney",oledbType.double)
objParam.value = params(9)
Dbcommand.parameters.add(objParam)
objParam = new oledbParameter("@PowerMoney",oledbType.double)
objParam.value = params(10)
Dbcommand.parameters.add(objParam)
objParam = new oledbParameter("@charterMoney",oledbType.double)
objParam.value = params(11)
Dbcommand.parameters.add(objParam)
objParam = new oledbParameter("@others",oledbType.double)
objParam.value = params(12)
Dbcommand.parameters.add(objParam)
objParam = new oledbParameter("@id",oledbType.integer)
objParam.value = DataGrid1.DataKeys(cint(e.item.itemIndex))
Dbcommand.parameters.add(objParam)
Dbcommand.connection.open
Try
DbCommand.ExecuteNonQuery()
lblMessage.InnerHtml = "¹§Ï²£¬ÄãÒѳɹ¦¸üÐÂÁËÊý¾Ý£¡
"
DataGrid1.EditItemIndex = -1
Catch Ex As oledbException
lblMessage.InnerHtml="Error message!"
end try
Dbcommand.connection.close
BindGrid()
end sub