在MS Access中插入记录 [英] Insert Record in MS Access

查看:113
本文介绍了在MS Access中插入记录的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

嗨!

我正在尝试使用以下步骤通过vb.net连接到MS Access:

1.从菜单栏中选择工具"
2.选择连接到数据库"
3.输入数据库的路径,然后单击测试连接".它将显示消息测试连接成功"

之后,我在表单中编写一些代码,在其中执行插入查询.代码是:

Hi!

I am trying to connect to MS access with vb.net using following steps:

1. Select "TOOL" from the menubar
2. Select "connect to database"
3. Enter the path of the database and click TEST CONNECTION. It will display the message "TEST CONNECTION SUCCESSFUL"

After that, I am writing some code in my form where I want to perform the insert query. The code is:

Imports System.Data.OleDb

Public Class Item_Info
    Dim cn As OleDbConnection
    Dim cmd As OleDbCommand
    Dim da As OleDbDataAdapter
    Dim dr As OleDbDataReader
    Dim str As String
    Dim icount As Integer

Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs)
        cn = "here i am putting my database path.. connectionstring"
        cn.Open()
        str = "insert into Item_Master values('" & txtName.Text & "','" & txtCode.Text & "')"
        cmd = New OleDbCommand(str, cn)
        cmd.ExecuteNonQuery()
        cn.Close()

    End Sub
End Class



但是,当我运行此表单时,它不会创建任何输出.它也不会给出任何错误……我不明白问题是什么.
请帮帮我!



But when I run this form it doesn''t create any output. Nor does it give any errors...... I don''t understand what the problem is.
Please help me!

推荐答案

也许像:
"insert into Item_Master (Name, Code) values(''" & txtName.Text & "'',''" & txtCode.Text & "'')"



欢呼声



Cheers


我看到的唯一问题可能是您的连接字符串.不过,在这种情况下,您应该会得到一个错误.

并且确定要执行cn = New OldDbConnection()吗?

Item_Master 在数据库中吗?

简单的问题,但是从您提供的内容来看,我看不到任何其他问题来源.

另外,检查cmd.ExecuteNonQuery() 返回的内容.如果成功,它将返回1.
The only problem that I see could be your connection string. Though, you should get an error if that was the case.

And did you make sure that you did cn = New OldDbConnection()?

And is Item_Master in the database?

Simple questions, but from what you''ve provided, I can''t see any other source of problems.

Also, check what cmd.ExecuteNonQuery() returns. It should return 1 if it was successful.


这篇关于在MS Access中插入记录的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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