帮助 ! -语法错误,我无法插入句子 [英] Help ! - Syntax Fail i INSERT INTO-sentence
问题描述
嗨!
我很难在数据库中添加新行.
我已经在此示例中尝试了该代码( http://support.microsoft.com/kb/301248 ) 带有单个列表,它可以正常工作,但是现在我试图在更多复杂的表格,代码崩溃.
I have tried the code in this example ( http://support.microsoft.com/kb/301248 ) with a single column table and it works OK, but now I’m trying to add a line in a more complex table and the code crashes.
我想其中的一些问题:
- 我的第一列是ID,它是一个自动编号,索引不重复–我未设置此字段,因为我想系统会添加是自动的–是正确的
- My first column is ID which is a Auto number , index not repeated – I’m not setting this field as I suppose the system adds is automatically – is that correct
- 我没有在新行中设置所有字段,我的表中有几列类型为DateTime,是/否,文本和正如我提到的ID字段.可能是我发送了一些未初始化的字段的问题,我该怎么办 所以没有问题? 我要说的是,表中的所有字段均未定义为必填"
- I’m not setting all the field in my new row, my table has several columns of types DateTime, yes/no, text and as I mentioned the ID field. Could it be the problem that I send some fields not initiated and how can I do so without problem ? I need to say that none of the fields in the table is defined as ‘compulsory’
我想不出任何其他原因,这是我的代码示例
I can not think of any more reasons, here is a sample of my code
顺便说一下,我的代码在" " es_stopplogg" )
B y the way, my code crashes at the line "my_dataadapter.Update(my_dsPubs, "es_stopplogg")
" ,显示失败消息语法错误,我无法插入句子"
" with a fail message "Syntax Fail i INSERT INTO-sentence"
您能帮助我吗!
Dim my_connstr 为 字符串
Dim my_connstr As String
; my_connstr = "Provider = Microsoft.Jet.OLEDB.4.0; Data Source =""C:\ Users \ htrendaf \ Documents \ 01_Skretting work \ Prosjekter 2011 \ proj-VB stopploggextractor \ DB \ skr_pn_V05.mdb""
my_connstr = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=""C:\Users\htrendaf\Documents\01_Skretting work\Prosjekter 2011\proj - VB stopploggextractor\DB\skr_pn_V05.mdb"""
; 暗 my_objCon 如 新建 System.Data.OleDb. OleDbConnection (my_connstr)
Dim my_objCon As New System.Data.OleDb.OleDbConnection(my_connstr)
; my_objCon.Open()
my_objCon.Open()
; 昏暗 my_dataadapter 新建 System.Data.OleDb. OleDbDataAdapter (,my_objCon)
Dim my_dataadapter As New System.Data.OleDb.OleDbDataAdapter("select * from es_stopplogg", my_objCon)
; 暗 my_dsPubs 如 新建 System.Data.数据集("Pubs" ; )
Dim my_dsPubs As New System.Data.DataSet("Pubs")
; my_dataadapter.FillSchema(my_dsPubs, SchemaType .Source, " es_stopplogg" )
my_dataadapter.FillSchema(my_dsPubs, SchemaType.Source, "es_stopplogg")
; my_dataadapter.Fill(my_dsPubs," es_stopplogg" )
my_dataadapter.Fill(my_dsPubs, "es_stopplogg")
; 暗 my_tbl 按 数据表
Dim my_tbl As DataTable
; my_tbl = my_dsPubs.Tables(" es_stopplogg" )
my_tbl = my_dsPubs.Tables("es_stopplogg")
; 昏暗 my_row As DataRow
Dim my_row As DataRow
; '*************************************** **********
'*********************************************
; '有效
' working
; '*************************************** **********
'*********************************************
; 将Dim dt设置为新的DateTime(Long.Parse(Me.Stopp))
'Dim dt As New DateTime(Long.Parse(Me.Stopp))
; my_row = my_tbl.NewRow
my_row = my_tbl.NewRow
; my_row(" Kommentar" )= "tryi'n new line 111"
my_row("Kommentar") = "tryi'n new line 111"
; my_row("Stopp" )= DateTime .现在
my_row("Stopp") = DateTime.Now
; my_row(开始" )= DateTime .现在
my_row("Start") = DateTime.Now
; my_row(Operatør" )= 我 .Operator_1.Text
my_row("Operatør") = Me.Operator_1.Text
; my_row("Skift" )= 我 .Skift.Text
my_row("Skift") = Me.Skift.Text
; my_row("KE-1" )= 真
my_row("KE-1") = True
; my_row("KE-2"; )= 错误
my_row("KE-2") = False
; 'my_row("Tag-nr/type")=''
'my_row("Tag-nr/type") = ""
; my_row("Stoppårsak" )= 我 .Aarsak.Text
my_row("Stoppårsak") = Me.Aarsak.Text
; 'my_row(Område")=
'my_row("Område") =
; my_tbl.Rows.Add(my_row)
my_tbl.Rows.Add(my_row)
; '----------------------------------- -----------
'----------------------------------------------
; 昏暗 my_commandBuilder 新建 Data.OleDb. OleDbCommandBuilder (my_dataadapter)
Dim my_commandBuilder As New Data.OleDb.OleDbCommandBuilder(my_dataadapter)
; my_dataadapter.Update(my_dsPubs," es_stopplogg" )
my_dataadapter.Update(my_dsPubs, "es_stopplogg")
; my_objCon.Close()
my_objCon.Close()
; my_objCon.Dispose()
my_objCon.Dispose()
推荐答案
我认为原因是您在插入查询中不包含主键.由于主键是自动编号,因此建议您不要使用这种方式添加新记录.
I think the reason is that you doesn't contain the primary key in the insert query. As the primary key is auto number, I will suggest you don't use this way to add a new record.
请尝试使用带有参数的插入命令.检查此链接中的示例: http://msdn.microsoft.com/zh-CN/library/system.data.oledb.oledbdataadapter.updatecommand
Please try to use insert command with parameters.Check the samples in this link:http://msdn.microsoft.com/en-us/library/system.data.oledb.oledbdataadapter.updatecommand
同时,您还需要检查设置为数据库的数据类型是否合适.
At the same time, you also need to check the data type you set to database whether suitable.
这篇关于帮助 ! -语法错误,我无法插入句子的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!