EDN Admin
Well-known member
<span lang="EN-US Hi!
<span lang="EN-US I’m having some difficulty to add a new line in my data base.
<span lang="EN-US I have tried the code in this example ( http://support.microsoft.com/kb/301248
http://support.microsoft.com/kb/301248 ) <span> 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.
<span lang="EN-US I suppose I have some problems with some of these:
<p style="text-indent:-18pt <span lang="EN-US <span>-<span style="font:7pt Times New Roman
<span lang="EN-US 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
<p style="text-indent:-18pt <span lang="EN-US <span>-<span style="font:7pt Times New Roman
<span lang="EN-US 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 ?<span> I need to say that none of the fields in the table is defined as ‘compulsory’
<span lang="EN-US I can not think of any more reasons, here is a sample of my code
<p style="line-height:normal; margin-bottom:0pt <span lang="EN-US B y the way, my code crashes at the line “<span lang="EN-US" style="font-family:Consolas; font-size:9.5pt my_dataadapter.Update(my_dsPubs,
<span style="color:#a31515 "es_stopplogg")
<span lang="EN-US “<span> with a fail message “Syntax Fail i INSERT INTO-sentence”
<span lang="EN-US Can you please help me !!!
<p style="line-height:normal; margin-bottom:0pt <span lang="EN-US" style="font-family:Consolas; color:blue; font-size:9.5pt Dim<span lang="EN-US" style="font-family:Consolas; font-size:9.5pt my_connstr
<span style="color:blue As <span style="color:blue String
<p style="line-height:normal; margin-bottom:0pt <span lang="EN-US" style="font-family:Consolas; font-size:9.5pt <span>
my_connstr = <span style="color:#a31515 "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=""C:UsershtrendafDocuments 1_Skretting workProsjekter 2011proj - VB stopploggextractorDBskr_pn_V05.mdb"""
<p style="line-height:normal; margin-bottom:0pt <span lang="EN-US" style="font-family:Consolas; font-size:9.5pt <span>
<span style="color:blue Dim my_objCon <span style="color:blue As
<span style="color:blue New System.Data.OleDb.<span style="color:#2b91af OleDbConnection(my_connstr)
<p style="line-height:normal; margin-bottom:0pt <span lang="EN-US" style="font-family:Consolas; font-size:9.5pt <span>
my_objCon.Open()
<p style="line-height:normal; margin-bottom:0pt
<p style="line-height:normal; margin-bottom:0pt <span lang="EN-US" style="font-family:Consolas; font-size:9.5pt <span>
<span style="color:blue Dim my_dataadapter <span style="color:blue
As <span style="color:blue New System.Data.OleDb.<span style="color:#2b91af OleDbDataAdapter(<span style="color:#a31515 "select * from es_stopplogg", my_objCon)
<p style="line-height:normal; margin-bottom:0pt <span lang="EN-US" style="font-family:Consolas; font-size:9.5pt <span>
<span style="color:blue Dim my_dsPubs <span style="color:blue As
<span style="color:blue New System.Data.<span style="color:#2b91af DataSet(<span style="color:#a31515 "Pubs")
<p style="line-height:normal; margin-bottom:0pt <span lang="EN-US" style="font-family:Consolas; font-size:9.5pt <span>
my_dataadapter.FillSchema(my_dsPubs, <span style="color:#2b91af SchemaType.Source,
<span style="color:#a31515 "es_stopplogg")
<p style="line-height:normal; margin-bottom:0pt <span lang="EN-US" style="font-family:Consolas; font-size:9.5pt <span>
my_dataadapter.Fill(my_dsPubs, <span style="color:#a31515 "es_stopplogg")
<p style="line-height:normal; margin-bottom:0pt <span lang="EN-US" style="font-family:Consolas; font-size:9.5pt <span>
<span style="color:blue Dim my_tbl <span style="color:blue As
<span style="color:#2b91af DataTable
<p style="line-height:normal; margin-bottom:0pt <span lang="EN-US" style="font-family:Consolas; font-size:9.5pt <span>
my_tbl = my_dsPubs.Tables(<span style="color:#a31515 "es_stopplogg")
<p style="line-height:normal; margin-bottom:0pt <span lang="EN-US" style="font-family:Consolas; font-size:9.5pt <span>
<span style="color:blue Dim my_row <span style="color:blue As
<span style="color:#2b91af DataRow
<p style="line-height:normal; margin-bottom:0pt
<p style="line-height:normal; margin-bottom:0pt <span lang="EN-US" style="font-family:Consolas; font-size:9.5pt <span>
<span style="color:green *********************************************
<p style="line-height:normal; margin-bottom:0pt <span lang="EN-US" style="font-family:Consolas; font-size:9.5pt <span>
<span style="color:green working
<p style="line-height:normal; margin-bottom:0pt <span lang="EN-US" style="font-family:Consolas; font-size:9.5pt <span>
<span style="color:green *********************************************
<p style="line-height:normal; margin-bottom:0pt <span lang="EN-US" style="font-family:Consolas; font-size:9.5pt <span>
<span style="color:green Dim dt As New DateTime(Long.Parse(Me.Stopp))
<p style="line-height:normal; margin-bottom:0pt <span lang="EN-US" style="font-family:Consolas; font-size:9.5pt <span>
my_row = my_tbl.NewRow
<p style="line-height:normal; margin-bottom:0pt <span lang="EN-US" style="font-family:Consolas; font-size:9.5pt <span>
my_row(<span style="color:#a31515 "Kommentar") = <span style="color:#a31515
"tryin new line 111"
<p style="line-height:normal; margin-bottom:0pt <span lang="EN-US" style="font-family:Consolas; font-size:9.5pt <span>
my_row(<span style="color:#a31515 "Stopp") = <span style="color:#2b91af
DateTime.Now
<p style="line-height:normal; margin-bottom:0pt <span lang="EN-US" style="font-family:Consolas; font-size:9.5pt <span>
my_row(<span style="color:#a31515 "Start") = <span style="color:#2b91af
DateTime.Now
<p style="line-height:normal; margin-bottom:0pt <span lang="EN-US" style="font-family:Consolas; font-size:9.5pt <span>
my_row(<span style="color:#a31515 "Operatør") = <span style="color:blue
Me.Operator_1.Text
<p style="line-height:normal; margin-bottom:0pt <span lang="EN-US" style="font-family:Consolas; font-size:9.5pt <span>
my_row(<span style="color:#a31515 "Skift") = <span style="color:blue
Me.Skift.Text
<p style="line-height:normal; margin-bottom:0pt <span lang="EN-US" style="font-family:Consolas; font-size:9.5pt <span>
<span> my_row(<span style="color:#a31515 "KE-1") = <span style="color:blue
True
<p style="line-height:normal; margin-bottom:0pt <span lang="EN-US" style="font-family:Consolas; font-size:9.5pt <span>
my_row(<span style="color:#a31515 "KE-2") = <span style="color:blue
False
<p style="line-height:normal; margin-bottom:0pt <span lang="EN-US" style="font-family:Consolas; font-size:9.5pt <span>
<span style="color:green my_row("Tag-nr/type") = ""
<p style="line-height:normal; margin-bottom:0pt <span lang="EN-US" style="font-family:Consolas; font-size:9.5pt <span>
my_row(<span style="color:#a31515 "Stoppårsak") = <span style="color:blue
Me.Aarsak.Text
<p style="line-height:normal; margin-bottom:0pt <span lang="EN-US" style="font-family:Consolas; font-size:9.5pt <span>
<span style="color:green my_row("Område") =
<p style="line-height:normal; margin-bottom:0pt
<p style="line-height:normal; margin-bottom:0pt <span lang="EN-US" style="font-family:Consolas; font-size:9.5pt <span>
my_tbl.Rows.Add(my_row)
<p style="line-height:normal; margin-bottom:0pt <span lang="EN-US" style="font-family:Consolas; font-size:9.5pt <span>
<span style="color:green ----------------------------------------------
<p style="line-height:normal; margin-bottom:0pt
<p style="line-height:normal; margin-bottom:0pt <span lang="EN-US" style="font-family:Consolas; font-size:9.5pt <span>
<span style="color:blue Dim my_commandBuilder <span style="color:blue
As <span style="color:blue New Data.OleDb.<span style="color:#2b91af OleDbCommandBuilder(my_dataadapter)
<p style="line-height:normal; margin-bottom:0pt <span lang="EN-US" style="font-family:Consolas; font-size:9.5pt <span>
my_dataadapter.Update(my_dsPubs, <span style="color:#a31515 "es_stopplogg")
<p style="line-height:normal; margin-bottom:0pt
<p style="line-height:normal; margin-bottom:0pt
<p style="line-height:normal; margin-bottom:0pt <span lang="EN-US" style="font-family:Consolas; font-size:9.5pt <span>
my_objCon.Close()
<p style="line-height:normal; margin-bottom:0pt <span lang="EN-US" style="font-family:Consolas; font-size:9.5pt <span>
my_objCon.Dispose()
View the full article
<span lang="EN-US I’m having some difficulty to add a new line in my data base.
<span lang="EN-US I have tried the code in this example ( http://support.microsoft.com/kb/301248
http://support.microsoft.com/kb/301248 ) <span> 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.
<span lang="EN-US I suppose I have some problems with some of these:
<p style="text-indent:-18pt <span lang="EN-US <span>-<span style="font:7pt Times New Roman
<span lang="EN-US 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
<p style="text-indent:-18pt <span lang="EN-US <span>-<span style="font:7pt Times New Roman
<span lang="EN-US 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 ?<span> I need to say that none of the fields in the table is defined as ‘compulsory’
<span lang="EN-US I can not think of any more reasons, here is a sample of my code
<p style="line-height:normal; margin-bottom:0pt <span lang="EN-US B y the way, my code crashes at the line “<span lang="EN-US" style="font-family:Consolas; font-size:9.5pt my_dataadapter.Update(my_dsPubs,
<span style="color:#a31515 "es_stopplogg")
<span lang="EN-US “<span> with a fail message “Syntax Fail i INSERT INTO-sentence”
<span lang="EN-US Can you please help me !!!
<p style="line-height:normal; margin-bottom:0pt <span lang="EN-US" style="font-family:Consolas; color:blue; font-size:9.5pt Dim<span lang="EN-US" style="font-family:Consolas; font-size:9.5pt my_connstr
<span style="color:blue As <span style="color:blue String
<p style="line-height:normal; margin-bottom:0pt <span lang="EN-US" style="font-family:Consolas; font-size:9.5pt <span>
my_connstr = <span style="color:#a31515 "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=""C:UsershtrendafDocuments 1_Skretting workProsjekter 2011proj - VB stopploggextractorDBskr_pn_V05.mdb"""
<p style="line-height:normal; margin-bottom:0pt <span lang="EN-US" style="font-family:Consolas; font-size:9.5pt <span>
<span style="color:blue Dim my_objCon <span style="color:blue As
<span style="color:blue New System.Data.OleDb.<span style="color:#2b91af OleDbConnection(my_connstr)
<p style="line-height:normal; margin-bottom:0pt <span lang="EN-US" style="font-family:Consolas; font-size:9.5pt <span>
my_objCon.Open()
<p style="line-height:normal; margin-bottom:0pt
<p style="line-height:normal; margin-bottom:0pt <span lang="EN-US" style="font-family:Consolas; font-size:9.5pt <span>
<span style="color:blue Dim my_dataadapter <span style="color:blue
As <span style="color:blue New System.Data.OleDb.<span style="color:#2b91af OleDbDataAdapter(<span style="color:#a31515 "select * from es_stopplogg", my_objCon)
<p style="line-height:normal; margin-bottom:0pt <span lang="EN-US" style="font-family:Consolas; font-size:9.5pt <span>
<span style="color:blue Dim my_dsPubs <span style="color:blue As
<span style="color:blue New System.Data.<span style="color:#2b91af DataSet(<span style="color:#a31515 "Pubs")
<p style="line-height:normal; margin-bottom:0pt <span lang="EN-US" style="font-family:Consolas; font-size:9.5pt <span>
my_dataadapter.FillSchema(my_dsPubs, <span style="color:#2b91af SchemaType.Source,
<span style="color:#a31515 "es_stopplogg")
<p style="line-height:normal; margin-bottom:0pt <span lang="EN-US" style="font-family:Consolas; font-size:9.5pt <span>
my_dataadapter.Fill(my_dsPubs, <span style="color:#a31515 "es_stopplogg")
<p style="line-height:normal; margin-bottom:0pt <span lang="EN-US" style="font-family:Consolas; font-size:9.5pt <span>
<span style="color:blue Dim my_tbl <span style="color:blue As
<span style="color:#2b91af DataTable
<p style="line-height:normal; margin-bottom:0pt <span lang="EN-US" style="font-family:Consolas; font-size:9.5pt <span>
my_tbl = my_dsPubs.Tables(<span style="color:#a31515 "es_stopplogg")
<p style="line-height:normal; margin-bottom:0pt <span lang="EN-US" style="font-family:Consolas; font-size:9.5pt <span>
<span style="color:blue Dim my_row <span style="color:blue As
<span style="color:#2b91af DataRow
<p style="line-height:normal; margin-bottom:0pt
<p style="line-height:normal; margin-bottom:0pt <span lang="EN-US" style="font-family:Consolas; font-size:9.5pt <span>
<span style="color:green *********************************************
<p style="line-height:normal; margin-bottom:0pt <span lang="EN-US" style="font-family:Consolas; font-size:9.5pt <span>
<span style="color:green working
<p style="line-height:normal; margin-bottom:0pt <span lang="EN-US" style="font-family:Consolas; font-size:9.5pt <span>
<span style="color:green *********************************************
<p style="line-height:normal; margin-bottom:0pt <span lang="EN-US" style="font-family:Consolas; font-size:9.5pt <span>
<span style="color:green Dim dt As New DateTime(Long.Parse(Me.Stopp))
<p style="line-height:normal; margin-bottom:0pt <span lang="EN-US" style="font-family:Consolas; font-size:9.5pt <span>
my_row = my_tbl.NewRow
<p style="line-height:normal; margin-bottom:0pt <span lang="EN-US" style="font-family:Consolas; font-size:9.5pt <span>
my_row(<span style="color:#a31515 "Kommentar") = <span style="color:#a31515
"tryin new line 111"
<p style="line-height:normal; margin-bottom:0pt <span lang="EN-US" style="font-family:Consolas; font-size:9.5pt <span>
my_row(<span style="color:#a31515 "Stopp") = <span style="color:#2b91af
DateTime.Now
<p style="line-height:normal; margin-bottom:0pt <span lang="EN-US" style="font-family:Consolas; font-size:9.5pt <span>
my_row(<span style="color:#a31515 "Start") = <span style="color:#2b91af
DateTime.Now
<p style="line-height:normal; margin-bottom:0pt <span lang="EN-US" style="font-family:Consolas; font-size:9.5pt <span>
my_row(<span style="color:#a31515 "Operatør") = <span style="color:blue
Me.Operator_1.Text
<p style="line-height:normal; margin-bottom:0pt <span lang="EN-US" style="font-family:Consolas; font-size:9.5pt <span>
my_row(<span style="color:#a31515 "Skift") = <span style="color:blue
Me.Skift.Text
<p style="line-height:normal; margin-bottom:0pt <span lang="EN-US" style="font-family:Consolas; font-size:9.5pt <span>
<span> my_row(<span style="color:#a31515 "KE-1") = <span style="color:blue
True
<p style="line-height:normal; margin-bottom:0pt <span lang="EN-US" style="font-family:Consolas; font-size:9.5pt <span>
my_row(<span style="color:#a31515 "KE-2") = <span style="color:blue
False
<p style="line-height:normal; margin-bottom:0pt <span lang="EN-US" style="font-family:Consolas; font-size:9.5pt <span>
<span style="color:green my_row("Tag-nr/type") = ""
<p style="line-height:normal; margin-bottom:0pt <span lang="EN-US" style="font-family:Consolas; font-size:9.5pt <span>
my_row(<span style="color:#a31515 "Stoppårsak") = <span style="color:blue
Me.Aarsak.Text
<p style="line-height:normal; margin-bottom:0pt <span lang="EN-US" style="font-family:Consolas; font-size:9.5pt <span>
<span style="color:green my_row("Område") =
<p style="line-height:normal; margin-bottom:0pt
<p style="line-height:normal; margin-bottom:0pt <span lang="EN-US" style="font-family:Consolas; font-size:9.5pt <span>
my_tbl.Rows.Add(my_row)
<p style="line-height:normal; margin-bottom:0pt <span lang="EN-US" style="font-family:Consolas; font-size:9.5pt <span>
<span style="color:green ----------------------------------------------
<p style="line-height:normal; margin-bottom:0pt
<p style="line-height:normal; margin-bottom:0pt <span lang="EN-US" style="font-family:Consolas; font-size:9.5pt <span>
<span style="color:blue Dim my_commandBuilder <span style="color:blue
As <span style="color:blue New Data.OleDb.<span style="color:#2b91af OleDbCommandBuilder(my_dataadapter)
<p style="line-height:normal; margin-bottom:0pt <span lang="EN-US" style="font-family:Consolas; font-size:9.5pt <span>
my_dataadapter.Update(my_dsPubs, <span style="color:#a31515 "es_stopplogg")
<p style="line-height:normal; margin-bottom:0pt
<p style="line-height:normal; margin-bottom:0pt
<p style="line-height:normal; margin-bottom:0pt <span lang="EN-US" style="font-family:Consolas; font-size:9.5pt <span>
my_objCon.Close()
<p style="line-height:normal; margin-bottom:0pt <span lang="EN-US" style="font-family:Consolas; font-size:9.5pt <span>
my_objCon.Dispose()
View the full article