更新访问数据库中的数据 [英] Updating Data in access database
本文介绍了更新访问数据库中的数据的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
试图更新访问数据库中的数据..没有显示错误但数据没有更新......可能出错?这是更新按钮下的一些代码。
On trying to update the data in access database..no error is displayed yet the data does not get updated...what could be wrong? here is some of the code under the update button.
connect()
'checking wherether centre number exists in database
Try
If Not cnn.State = ConnectionState.Open Then
'open connection if it is not yet open
cnn.Open()
End If
cmd.Connection = cnn
cmd.CommandText = "SELECT count(motonum) from moto where motonum = '" & TextBox1.Text & "'"
myData = cmd.ExecuteReader
While myData.Read()
dcount = myData(0)
End While
myData.Close()
'if number exists.......
MessageBox.Show(dcount)
If dcount <> 0 And Me.TextBox1.Text <> Me.TextBox1.Tag Then
MsgBox("Centre number " & TextBox1.Text + " is Already Registered. Please Try another Number!", MsgBoxStyle.Critical)
'if number doesnt exist......update
Else
cmd.CommandText = "UPDATE moto " & _
" SET motonum='" & Me.TextBox1.Text & _
"', motocat='" & Me.TextBox1.Text.Trim & "'" & _
"where motonum='" & Me.TextBox1.Tag & "'"
cmd.ExecuteNonQuery()
MessageBox.Show("updated")
End If
Catch ex As Exception
MessageBox.Show(ex.ToString)
End Try
推荐答案
谁知道?你不 - 我们不 - 而且我们都没有人知道,因为你丢失了关于错误原因的任何和所有信息。
当你使用一个空的Catch
块时,你说我不在乎错误是什么,让我们忽略它并继续。
添加一些代码 - 至少:
Who knows? You don''t - and we don''t - and none of us can find out, because you are throwing away any and all information on the cause of the error.
When you use an emptyCatch
block, you are saying "I don''t care what the error is, let''s ignore it and continue".
Add some code - at a bare minimum:
Catch ex As Exception
MessageBox.Show(ex.Message)
End Try
这将让您开始找到问题所引起的问题!
Which will give you a start of finding what the problem is caused by!
这篇关于更新访问数据库中的数据的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文