在vb.net和访问中更新记录的问题 [英] problem updating record in vb.net and access

查看:67
本文介绍了在vb.net和访问中更新记录的问题的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

大家好..



有人可以指导我,如何更新vb.net中的某些记录并访问?我很难做到这一点..很多方法我尝试..但是,仍然没有任何变化..最新的一个,我做..我点击更新按钮后我什么也没有结果。



这是我的代码到目前为止。



hi everyone..

can someone guide me, how to update certain record in vb.net and access? i have difficulties to do this.. many ways i have try.. but, still nothing changes.. the latest one, i do.. i will result nothing after i clicked the update button.

this is my code so far.

' to do coding renew thesis
    Private Sub renewBtn_Click(sender As Object, e As EventArgs) Handles renewBtn.Click

        Dim cmdupdate As OleDbCommand = New OleDbCommand

        If idsearchtxt.Text <> "" And namerenewl.Text <> "" And Lemail.Text <> "" And icNoRenew.Text <> "" And codeLabel.Text <> "" And renewTitleL.Text <> "" And authorRenew.Text <> "" And yearRenew.Text <> "" And renewDtp.Text <> "" And renewDue.Text <> "" Then

            cmdupdate.CommandText = "UPDATE BorrowThesis SET [Stud Name] = '" & namerenewl.Text & "'," _
     & "[Email] = '" & Lemail.Text & "'," _
     & "[IC No] = '" & icNoRenew.Text & "'," _
     & "[Thesis Code] = '" & codeLabel.Text & "'," _
    & "[Title] = '" & renewTitleL.Text & "'," _
    & "[Author] = '" & authorRenew.Text & "'," _
    & "[Year] = '" & yearRenew.Text & "'," _
   & "[Date borrow] = '" & renewDtp.Text & "'," _
  & "[Due date] = '" & renewDue.Text & "'," _
 & "WHERE Matric No = '" & idsearchtxt.Text & "'"


                con.Open()
                ' cmdupdate = New OleDbCommand(cmdupdate, con)
                cmdupdate.CommandType = CommandType.Text
                cmdupdate.Connection = con
                cmdupdate.ExecuteNonQuery()

                MsgBox(idsearchtxt.Text = "Record updated.")
                namerenewl.Text = ""
                Lemail.Text = ""
                icNoRenew.Text = ""
                codeLabel.Text = ""
                renewTitleL.Text = ""
                authorRenew.Text = ""
                yearRenew.Text = ""
                renewDtp.Text = ""
                renewDue.Text = ""

            Me.BorrowThesisTableAdapter.Insert(idsearchtxt.Text, namerenewl.Text, Lemail.Text, icNoRenew.Text, codeLabel.Text, renewTitleL.Text, authorRenew.Text, yearRenew.Text, renewDtp.Text, renewDue.Text)
                Me.BorrowThesisTableAdapter.Fill(Me.ThesisDBDataSet.BorrowThesis)
                Me.BorrowThesisTableAdapter.Update(Me.ThesisDBDataSet.BorrowThesis)

          
        End If
        cmdupdate.Dispose()
        con.Close()

    End Sub

推荐答案

有几件事要检查:

There are few things to check:


  1. [IC No] [年] [Matric No] 是数字数据类型字段?
  2. 如果是,您应该删除' sign < br $>
  3. [借用日期] [截止日期] 是日期数据类型字段?
  4. 如果是,您应该使用而不是'

  5. 不接受 Matric No 的名称
  6. 添加括号: [Matric No]


  1. Does [IC No], [Year], [Matric No] is numeric data type field?
  2. If yes, you should remove ' sign
  3. Does [Date borrow] and [Due date] is date data type field?
  4. If yes, you should use # instead of '
  5. The name of Matric No is not accepted
  6. Add brackets: [Matric No]



最后,您的更新查询应如下所示:


Finally, your update query should looks like that:

= "UPDATE BorrowThesis SET [Stud Name] = '" & namerenewl.Text & "'," _
    & "[Email] = '" & Lemail.Text & "'," _
    & "[IC No] = " & icNoRenew.Text & "," _
    & "[Thesis Code] = '" & codeLabel.Text & "'," _
   & "[Title] = '" & renewTitleL.Text & "'," _
   & "[Author] = '" & authorRenew.Text & "'," _
   & "[Year] = " & yearRenew.Text & "," _
  & "[Date borrow] = #" & renewDtp.Text & "#," _
 & "[Due date] = #" & renewDue.Text & "#," _
& "WHERE [Matric No] = " & idsearchtxt.Text & ""





如需了解更多信息,请参阅:

MS Access数据类型 [ ^ ]

Access 2007中的查询提示和技巧 [ ^ ]


这篇关于在vb.net和访问中更新记录的问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆