使用 vb.net 更新微软访问记录 [英] updating a microsoft access record using vb.net

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

问题描述

到现在为止,我一直在尝试更新此记录近 3 天,在整个互联网上都找不到任何帮助我的东西,尝试了所有解决方案,但一无所获.

I have been trying to update this record for almost 3 days by now, been round all the Internet and can't find anything that helps me, tried all the solutions but nothing.

我想更新一个记录,这个表格叫做search form,表格由 8 列组成,其中 student_id 是一个 autonumber 所以我没有搞砸.

I want to update a record, the form is called search form, table consists of 8 columns where student_id is an autonumber so I didn't mess up with it.

这是我想出的最后一个,但它仍然无法正常工作,它突出显示了 executenonquery() 并在按下按钮后给出一条错误消息,表示 no values where given到一个或多个必需参数 ...

This is the last that I came up with and it's still not working, it highlights the executenonquery() and gives an error message after pressing the button, that says no values where given to one or more required parameters ...

Dim con As New OleDb.OleDbConnection("Provider=Microsoft.Jet.OLEDB.4.0;Data Source=C:\Users\Anton\Desktop\LoginDatabase\Users.mdb")
        con.Open()
       sql = "update salary set [empname]=?,[department]=?,[date1]=?, [accname]= ?,[accnumber]=?,[backname]=?,[rate]=?,[house]=?,[electricity]=?,[travel]=?, [hardship]= ?,[health]=?,[nhif]=?,[nssf]=?,[insurence]=?,[loan]=?,[welfare]=? where empno = ?"
    Dim cmd As New OleDb.OleDbCommand(sql, con)

    cmd.Parameters.AddWithValue("@empname", TextBox2.Text)
    cmd.Parameters.AddWithValue("@department", TextBox3.Text)
    cmd.Parameters.AddWithValue("@date1", DateTimePicker1.Value)
    cmd.Parameters.AddWithValue("@accname", TextBox4.Text)
    cmd.Parameters.AddWithValue("@accnumber", TextBox5.Text)
    cmd.Parameters.AddWithValue("@bankname", TextBox6.Text)
    cmd.Parameters.AddWithValue("@rate", TextBox7.Text)
    cmd.Parameters.AddWithValue("@house", TextBox8.Text)
    cmd.Parameters.AddWithValue("@electricity", TextBox9.Text)
    cmd.Parameters.AddWithValue("@travel", TextBox10.Text)
    cmd.Parameters.AddWithValue("@hardship", TextBox11.Text)
    cmd.Parameters.AddWithValue("@health", TextBox12.Text)
    cmd.Parameters.AddWithValue("@nhif", TextBox13.Text)
    cmd.Parameters.AddWithValue("@nssf", TextBox14.Text)
    cmd.Parameters.AddWithValue("@insurence", TextBox15.Text)
    cmd.Parameters.AddWithValue("@loan", TextBox16.Text)
    cmd.Parameters.AddWithValue("@welfare", TextBox17.Text)
    cmd.Parameters.AddWithValue("@empno", TextBox1.Text)
    Try
        cmd.ExecuteNonQuery()
        cmd.Dispose()
        MsgBox("updated")
    Catch ex As Exception
        MsgBox(ex.Message)
    End Try

推荐答案

您的错误是您在 SQL 语句中拼错了 BankName.使用[bankname]=?".

但是,替换表单并使用 Visual Studio 的本机功能要容易得多,如下所示:

However, it is FAR easier to replace your form and use the native functions of Visual Studio, as follows:

  1. 打开服务器资源管理器,点击连接到数据库并连接到您的 MDB 文件.
  2. 从菜单中选择数据 > 显示数据源.点击添加新数据源按钮.
  3. 在数据源"窗格中,使用添加新数据源,依次选择数据库"和数据集",完成向导并选择薪水"表.将创建一个数据集并将其放入您的项目中,您将在数据源"窗格中看到它.
  4. 无需关闭数据源"窗格,创建一个新的空白表单,它将在设计视图中打开.
  5. 点击表名salary"节点,下拉组合框以选择详细信息.
  6. 以相同方式展开表格并下拉 date1 列,以确保使用 DateTimePicker 控件.
  7. 将工资表从数据源窗格拖到新的空白表单上.
  1. Open the Server Explorer, click Connect to a Database and connect to your MDB file.
  2. From the menu, choose Data > Show Data Sources. Click the Add new Data Source button.
  3. From the Data Sources pane, use Add New Datasource, pick Database then Dataset, finish the wizard and choose the Salary table. A dataset will be created and placed into your project, and you will see it in your Data Sources pane.
  4. Without closing the Data Sources pane, Create a new blank form, and it will open in design view.
  5. Click the table name "salary" node, and drop down the combo-box to choose Details.
  6. Expand the table and drop down the date1 column in the same manner to make sure that the DateTimePicker control is used.
  7. Drag the Salary table from the Data Sources pane onto your new blank form.

一个带有导航栏的表单将出现在您的眼前.将创建一个以您的数据库名称命名的新数据集.

A form with a navigation bar will appear before your eyes. A new DataSet by the name of your database will be created.

对于以前的 MS Access 用户来说,这将是一个更直观的表单,并且您不需要像上面的问题一样手动创建任何 Insert 语句.

This will be a MUCH more intuitive form for former MS Access users, and you don't need to create any Insert statements manually, as in your question above.

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

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