帮助访问“插入"命令 [英] Help With Access "Insert Into" Command

查看:65
本文介绍了帮助访问“插入"命令的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

大家好,

我在Framework4上使用vb.net-我有一个带有datagrid(readonly)的表格,该表格从Access(MDB)读取数据.该表单还具有9个文本框.我希望能够在文本框中输入文本,然后刷新数据网格以显示添加的数据...我不明白问题是什么,我一直遇到错误-"INSERT INTO语句中的语法错误".谁能看到任何不正确的东西,我的数据库中的所有字段都是正确的.

Hi All,

i am using vb.net on framework4 - i have a form with datagrid(readonly) reading data from a Access(MDB). The form also has 9 textboxes. I want to beable to entered text into the textbox and then refresh the datagrid to display the added data...i dont understand what the issue is i keep getting a error - "Syntax error in INSERT INTO statement." can anyone see anything thats not correct, all my fields are correct from my database.

Dim con As New OleDb.OleDbConnection
      Dim cmd As New OleDb.OleDbCommand
      Dim eep As New String("Provider=Microsoft.Jet.OLEDB.4.0;Data Source=C:\odis\carlog.mdb")
      con.ConnectionString = eep

      con.Open()


      'Add To Table
      cmd.Connection = con
      cmd.CommandText = "INSERT INTO CARLOG(ID, CARID, TIME, DATE, MAKE, MODEL, REG, COMPANY, OWNER)" & _
                        " VALUES (" & Me.TextBox1.Text & ",'" & Me.TextBox2.Text & "','" & Me.TextBox3.Text & "','" & Me.TextBox4.Text & "','" & Me.TextBox5.Text & "','" & Me.TextBox6.Text & "','" & Me.TextBox7.Text & "','" & Me.TextBox8.Text & "','" & Me.TextBox9.Text & "')"

      cmd.ExecuteNonQuery()

      con.Close()



任何帮助或指针将不胜感激! :)

在此先感谢

-Steve



Any help or pointers would be muchh appreciated! :)

Thanks In Advance

- Steve

推荐答案

使用参数化查询来避免SQL注入.示例:

http://msdn.microsoft.com/en-us/library/bb738521.aspx [ ^ ]

另外,请勿将保留字用作列/表名.
MS Access中保留字的列表:

http://support.microsoft.com/kb/286335 [
use parametrized queries for avoiding SQL injection. Example:

http://msdn.microsoft.com/en-us/library/bb738521.aspx[^]

Also, do not use reserved words as column/table names.
List of reserved words in MS Access:

http://support.microsoft.com/kb/286335[^]

If you still want to use the query you are using then enclose the column name in brackets which are reserved words. example:

cmd.CommandText = "INSERT INTO CARLOG (ID, CARID, [TIME], [DATE], MAKE, MODEL, REG, COMPANY, OWNER)" & _


这篇关于帮助访问“插入"命令的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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