Re: My Brain Hurts - Help
Bernie,
There always was a try catch around the whole shebang. The whole procedure
is as follows:
Dim strSQL As String, dt As Data.DataTable, da As
OleDb.OleDbData Adapter, cb As OleDb.OleDbComm andBuilder
Dim rw As Data.DataRow, r As Long
Try 'First do Primary Client Details
If NewRecord Then
strSQL = "Select Clients.* FROM Clients ORDER BY ClientID;"
Else
strSQL = "Select * from Clients WHERE ClientID = " &
CurrentClientID
End If
da = New OleDb.OleDbData Adapter(strSQL, Conn) 'Create data
adapter
cb = New OleDb.OleDbComm andBuilder(da) 'Create command builder
using the datadapter
dt = New Data.DataTable
da.Fill(dt) 'pour in the data using the adapter
If NewRecord Then 'If doing a new record, begin edit and get
next id number
rw = dt.NewRow
rw("ClientID") = 2 'GetNextIDNumbe r("Clients")
CurrentClientID = 2 'rw("ClientID") 'Set the currentClientID
to this new client
rw("RelatedClie ntLinkID") = CurrentRelatedC lientID 'Type
is: Long.
rw("AdviserLink ID") = 0
rw("IsPrimaryCl ient") = True
rw("Title") = txtTitleSelf.Te xt 'Type is: String.
rw("Forename") = txtForenameSelf .Text 'Type is: String.
rw("OtherNames" ) = txtOtherNameSel f.Text 'Type is: String.
rw("Surname") = txtSurnameSelf. Text 'Type is: String.
rw("Relationshi pToPartner") = txtRelToPartner Self.Text
'Type is: String.
rw("DOB") = Now 'txtDOBYYYYSelf .Text & "-" &
txtDOBMMSelf.Te xt & "-" & txtDOBDDSelf.Te xt 'Type is: Date.
rw("StateOfHeal th") = txtStateOfHealt hSelf.Text 'Type is:
String.
rw("SmokerYN") = chkSmokerSelf.C hecked 'Type is: Boolean.
rw("Notes") = txtNotesSelf.Te xt 'Type is: String.
rw("NI Number") = "" 'Type is: String.
rw("TaxCode") = "" 'Type is: String.
rw("Income") = 0 'Type is: Single.
rw("SalaryOTBon us") = 0 'Type is: Single.
rw("SalaryRevie wDate") = Now 'Type is: Date.
rw("InvPensInco me") = 0 'Type is: Single.
rw("SelfEmpNetR elEarnings") = 0 'Type is: Single.
rw("TaxRatePerc entage") = 0 'Type is: Single.
rw("NetIncome" ) = 0 'Type is: Single.
rw("BenefitsInK indYN") = False 'Type is: Boolean.
rw("BenefitDesc 1") = "" 'Type is: String.
rw("BenefitValu e1") = 0 'Type is: Decimal.
rw("BenefitDesc 2") = "" 'Type is: String.
rw("BenefitValu e2") = 0 'Type is: Decimal.
rw("BenefitDesc 3") = "" 'Type is: String.
rw("BenefitValu e3") = 0 'Type is: Decimal.
rw("DateCreated ") = Now 'Type is: Date.
rw("User") = CurrentUser 'Type is String
dt.Rows.Add(rw) 'Add the new row
da.Update(dt) 'Send the update to the actual database using
the adapter
Else 'We're just modifying it
dt.Rows(r).Item ("RelatedClient LinkID") =
CurrentRelatedC lientID 'Type is: Long.
dt.Rows(r).Item ("Title") = txtTitleSelf.Te xt 'Type is:
String.
dt.Rows(r).Item ("Forename") = txtForenameSelf .Text 'Type
is: String.
dt.Rows(r).Item ("OtherNames ") = txtOtherNameSel f.Text 'Type
is: String.
dt.Rows(r).Item ("Surname") = txtSurnameSelf. Text 'Type is:
String.
dt.Rows(r).Item ("RelationshipT oPartner") =
txtRelToPartner Self.Text 'Type is: String.
dt.Rows(r).Item ("DOB") = txtDOBYYYYSelf. Text & "-" &
txtDOBMMSelf.Te xt & "-" & txtDOBDDSelf.Te xt 'Type is: Date.
dt.Rows(r).Item ("StateOfHealth ") = txtStateOfHealt hSelf.Text
'Type is: String.
dt.Rows(r).Item ("SmokerYN") = chkSmokerSelf.C hecked 'Type
is: Boolean.
dt.Rows(r).Item ("Notes") = txtNotesSelf.Te xt 'Type is:
String.
dt.Rows(r).Item ("DateCreate d") = Now 'Type is: Date.
dt.Rows(r).Item ("User") = CurrentUser 'Type is String
da.Update(dt) 'Send update to database
End If
dt.Dispose()
da.Dispose()
Catch ex As Exception
Call ProgErrorHandle r("SaveData - Primary Client Data",
"frmCust", ex.Message, False)
End Try
'============== =============== =============== =============
You'll see that I have started modifying the New side of the If statement to
include all fields with values and this made no difference.
"NewRecord" is passed to this sub to tell it to do a new rather than an
amend.
"ProgErrorHandl er" is a generic routine that just throws up a messagebox
detailing the error that has occurred.
The "Type is" comments are generated by a VBA macro that dumps the field
names and their types into a text file that I can copy into VB.NET to save
time getting all the field names and their types. Be aware that this is
quoting Access variable types (It is an outstanding job to modify that
routine so that it translates Access variables into VB.NET variable types)
which is where I was getting my Long data types confused.
--
Siv
Martley, Worcester, UK.
"Bernie Yaeger" <berniey@cherwe llinc.com> wrote in message
news:eKh82Ke8EH A.3504@TK2MSFTN GP12.phx.gbl...[color=blue]
> Hi Siv,
>
> Did you set up the try...catch block?
>
> Bernie
>
> "Siv" <msnewsgroups@r emoveme.sivill. com> wrote in message
> news:O4KejGe8EH A.1228@tk2msftn gp13.phx.gbl...[color=green]
>> Bernie,
>>
>> I had a look at that after your comment about the date field, as I do
>> tend to get tripped up by variable types (VB6 allowed us to get away with
>> a lot of implied conversions that just aren't allowed in VB.NET). I went
>> through all the fields in the table in Access to check that the text
>> fields would allow zero length strings and that I was populating any
>> fields that are required.
>>
>> In fact I tried adding the record manually through access only entering
>> the fields that the program is and it works fine.
>>
>> One thing I have been getting tripped up on is the difference between
>> "Long" in Access and "Long" in VB.NET. I did have a couple of fields
>> where I was using Longs in VB.NET and they were going into fields which
>> are Access "Longs" but should have been VB.NET Integers. I changed the
>> VB.NET code so that the fields in question were being assigned Integers
>> and it made no difference?
>>
>> It really is confusing!
>>
>>
>> --
>> Siv
>> Martley, Worcester, UK.
>>
>> "Bernie Yaeger" <berniey@cherwe llinc.com> wrote in message
>> news:uppzF%23d8 EHA.3708@TK2MSF TNGP14.phx.gbl. ..[color=darkred]
>>> Hi Siv,
>>>
>>> Here's another idea: are any of the textboxes empty and are they trying
>>> to fill a column that does not allow nulls? Just a thought.
>>>
>>> Bernie
>>>
>>> "Siv" <msnewsgroups@r emoveme.sivill. com> wrote in message
>>> news:Od586qd8EH A.3376@TK2MSFTN GP12.phx.gbl...
>>>> Bernie,
>>>>
>>>> Tried it and this didn't make any difference. BAAHHH!
>>>> What I don't get is that the CommandBuilder object should create the
>>>> Insert command for me automatically based on the select query.
>>>> Why would Dot Net be getting it wrong with such a simple SQL
>>>> statement??
>>>> I've looked at other routines where I use the same technique and it
>>>> works and I can't see what is different between them?
>>>> --
>>>> Siv
>>>> Martley, Worcester, UK.
>>>>
>>>> "Bernie Yaeger" <berniey@cherwe llinc.com> wrote in message
>>>> news:u1VdPbd8EH A.2608@TK2MSFTN GP10.phx.gbl...
>>>> Hi Siv,
>>>>
>>>> I think your problem is with the dob column. You are sending it text
>>>> but it requires date data. Wrap it in "#" on both ends and see what
>>>> happens. Also, just to verify my belief, simply change it to now.date
>>>> to see if that is indeed the problem.
>>>>
>>>> HTH,
>>>>
>>>> Bernie Yaeger
>>>>
>>>> "Siv" <msnewsgroups@r emoveme.sivill. com> wrote in message
>>>> news:ekSZ7Nd8EH A.1524@TK2MSFTN GP09.phx.gbl...
>>>> Hi,
>>>> If I run the following:
>>>>
>>>> strSQL = "Select * FROM Clients;"
>>>>
>>>> da = New OleDb.OleDbData Adapter(strSQL, Conn) 'Create data
>>>> adapter
>>>> cb = New OleDb.OleDbComm andBuilder(da) 'Create command
>>>> builder using the datadapter
>>>> dt = New Data.DataTable
>>>> da.Fill(dt) 'pour in the data using the adapter
>>>>
>>>> rw = dt.NewRow
>>>> rw("ClientID") = GetNextIDNumber ("Clients")
>>>>
>>>> CurrentClientID = CLng(rw("Client ID")) 'Set
>>>> the currentClientID to this new client
>>>>
>>>> rw("RelatedClie ntLinkID") = CurrentRelatedC lientID 'Type is:
>>>> Long.
>>>> rw("IsPrimaryCl ient") = True
>>>> rw("Title") = txtTitleSelf.Te xt 'Type is: String.
>>>> rw("Forename") = txtForenameSelf .Text 'Type is:
>>>> String.
>>>> rw("OtherNames" ) = txtOtherNameSel f.Text 'Type is:
>>>> String.
>>>> rw("Surname") = txtSurnameSelf. Text 'Type is:
>>>> String.
>>>> rw("Relationshi pToPartner") = txtRelToPartner Self.Text 'Type is:
>>>> String.
>>>> rw("DOB") = txtDOBYYYYSelf. Text & "-" & txtDOBMMSelf.Te xt & "-" &
>>>> txtDOBDDSelf.Te xt 'Type is: Date.
>>>> rw("StateOfHeal th") = txtStateOfHealt hSelf.Text 'Type is:
>>>> String.
>>>> rw("SmokerYN") = chkSmokerSelf.C hecked 'Type is:
>>>> Boolean.
>>>> rw("Notes") = txtNotesSelf.Te xt 'Type
>>>> is: String.
>>>> rw("DateCreated ") = Now
>>>> 'Type is: Date.
>>>> rw("User") = CurrentUser 'Type is String
>>>> dt.Rows.Add(rw) 'Add the new row
>>>> da.Update(dt) 'Send the update to the actual database using
>>>> the adapter
>>>>
>>>> At the da.Update(dt) line I det an exception thrown: "Syntax error in
>>>> INSERT INTO statement."
>>>>
>>>> I have other code that uses the same technique and I don't get an error
>>>> at all. I have tried changing the strSQL text so that it is more
>>>> complex and it makes no difference.
>>>> If anyone can see the glaring mistake that I am making please put me
>>>> out of my misery!
>>>>
>>>> Siv
>>>> Martley, Worcester, UK.
>>>>
>>>
>>>[/color]
>>
>>[/color]
>
>[/color]
Bernie,
There always was a try catch around the whole shebang. The whole procedure
is as follows:
Dim strSQL As String, dt As Data.DataTable, da As
OleDb.OleDbData Adapter, cb As OleDb.OleDbComm andBuilder
Dim rw As Data.DataRow, r As Long
Try 'First do Primary Client Details
If NewRecord Then
strSQL = "Select Clients.* FROM Clients ORDER BY ClientID;"
Else
strSQL = "Select * from Clients WHERE ClientID = " &
CurrentClientID
End If
da = New OleDb.OleDbData Adapter(strSQL, Conn) 'Create data
adapter
cb = New OleDb.OleDbComm andBuilder(da) 'Create command builder
using the datadapter
dt = New Data.DataTable
da.Fill(dt) 'pour in the data using the adapter
If NewRecord Then 'If doing a new record, begin edit and get
next id number
rw = dt.NewRow
rw("ClientID") = 2 'GetNextIDNumbe r("Clients")
CurrentClientID = 2 'rw("ClientID") 'Set the currentClientID
to this new client
rw("RelatedClie ntLinkID") = CurrentRelatedC lientID 'Type
is: Long.
rw("AdviserLink ID") = 0
rw("IsPrimaryCl ient") = True
rw("Title") = txtTitleSelf.Te xt 'Type is: String.
rw("Forename") = txtForenameSelf .Text 'Type is: String.
rw("OtherNames" ) = txtOtherNameSel f.Text 'Type is: String.
rw("Surname") = txtSurnameSelf. Text 'Type is: String.
rw("Relationshi pToPartner") = txtRelToPartner Self.Text
'Type is: String.
rw("DOB") = Now 'txtDOBYYYYSelf .Text & "-" &
txtDOBMMSelf.Te xt & "-" & txtDOBDDSelf.Te xt 'Type is: Date.
rw("StateOfHeal th") = txtStateOfHealt hSelf.Text 'Type is:
String.
rw("SmokerYN") = chkSmokerSelf.C hecked 'Type is: Boolean.
rw("Notes") = txtNotesSelf.Te xt 'Type is: String.
rw("NI Number") = "" 'Type is: String.
rw("TaxCode") = "" 'Type is: String.
rw("Income") = 0 'Type is: Single.
rw("SalaryOTBon us") = 0 'Type is: Single.
rw("SalaryRevie wDate") = Now 'Type is: Date.
rw("InvPensInco me") = 0 'Type is: Single.
rw("SelfEmpNetR elEarnings") = 0 'Type is: Single.
rw("TaxRatePerc entage") = 0 'Type is: Single.
rw("NetIncome" ) = 0 'Type is: Single.
rw("BenefitsInK indYN") = False 'Type is: Boolean.
rw("BenefitDesc 1") = "" 'Type is: String.
rw("BenefitValu e1") = 0 'Type is: Decimal.
rw("BenefitDesc 2") = "" 'Type is: String.
rw("BenefitValu e2") = 0 'Type is: Decimal.
rw("BenefitDesc 3") = "" 'Type is: String.
rw("BenefitValu e3") = 0 'Type is: Decimal.
rw("DateCreated ") = Now 'Type is: Date.
rw("User") = CurrentUser 'Type is String
dt.Rows.Add(rw) 'Add the new row
da.Update(dt) 'Send the update to the actual database using
the adapter
Else 'We're just modifying it
dt.Rows(r).Item ("RelatedClient LinkID") =
CurrentRelatedC lientID 'Type is: Long.
dt.Rows(r).Item ("Title") = txtTitleSelf.Te xt 'Type is:
String.
dt.Rows(r).Item ("Forename") = txtForenameSelf .Text 'Type
is: String.
dt.Rows(r).Item ("OtherNames ") = txtOtherNameSel f.Text 'Type
is: String.
dt.Rows(r).Item ("Surname") = txtSurnameSelf. Text 'Type is:
String.
dt.Rows(r).Item ("RelationshipT oPartner") =
txtRelToPartner Self.Text 'Type is: String.
dt.Rows(r).Item ("DOB") = txtDOBYYYYSelf. Text & "-" &
txtDOBMMSelf.Te xt & "-" & txtDOBDDSelf.Te xt 'Type is: Date.
dt.Rows(r).Item ("StateOfHealth ") = txtStateOfHealt hSelf.Text
'Type is: String.
dt.Rows(r).Item ("SmokerYN") = chkSmokerSelf.C hecked 'Type
is: Boolean.
dt.Rows(r).Item ("Notes") = txtNotesSelf.Te xt 'Type is:
String.
dt.Rows(r).Item ("DateCreate d") = Now 'Type is: Date.
dt.Rows(r).Item ("User") = CurrentUser 'Type is String
da.Update(dt) 'Send update to database
End If
dt.Dispose()
da.Dispose()
Catch ex As Exception
Call ProgErrorHandle r("SaveData - Primary Client Data",
"frmCust", ex.Message, False)
End Try
'============== =============== =============== =============
You'll see that I have started modifying the New side of the If statement to
include all fields with values and this made no difference.
"NewRecord" is passed to this sub to tell it to do a new rather than an
amend.
"ProgErrorHandl er" is a generic routine that just throws up a messagebox
detailing the error that has occurred.
The "Type is" comments are generated by a VBA macro that dumps the field
names and their types into a text file that I can copy into VB.NET to save
time getting all the field names and their types. Be aware that this is
quoting Access variable types (It is an outstanding job to modify that
routine so that it translates Access variables into VB.NET variable types)
which is where I was getting my Long data types confused.
--
Siv
Martley, Worcester, UK.
"Bernie Yaeger" <berniey@cherwe llinc.com> wrote in message
news:eKh82Ke8EH A.3504@TK2MSFTN GP12.phx.gbl...[color=blue]
> Hi Siv,
>
> Did you set up the try...catch block?
>
> Bernie
>
> "Siv" <msnewsgroups@r emoveme.sivill. com> wrote in message
> news:O4KejGe8EH A.1228@tk2msftn gp13.phx.gbl...[color=green]
>> Bernie,
>>
>> I had a look at that after your comment about the date field, as I do
>> tend to get tripped up by variable types (VB6 allowed us to get away with
>> a lot of implied conversions that just aren't allowed in VB.NET). I went
>> through all the fields in the table in Access to check that the text
>> fields would allow zero length strings and that I was populating any
>> fields that are required.
>>
>> In fact I tried adding the record manually through access only entering
>> the fields that the program is and it works fine.
>>
>> One thing I have been getting tripped up on is the difference between
>> "Long" in Access and "Long" in VB.NET. I did have a couple of fields
>> where I was using Longs in VB.NET and they were going into fields which
>> are Access "Longs" but should have been VB.NET Integers. I changed the
>> VB.NET code so that the fields in question were being assigned Integers
>> and it made no difference?
>>
>> It really is confusing!
>>
>>
>> --
>> Siv
>> Martley, Worcester, UK.
>>
>> "Bernie Yaeger" <berniey@cherwe llinc.com> wrote in message
>> news:uppzF%23d8 EHA.3708@TK2MSF TNGP14.phx.gbl. ..[color=darkred]
>>> Hi Siv,
>>>
>>> Here's another idea: are any of the textboxes empty and are they trying
>>> to fill a column that does not allow nulls? Just a thought.
>>>
>>> Bernie
>>>
>>> "Siv" <msnewsgroups@r emoveme.sivill. com> wrote in message
>>> news:Od586qd8EH A.3376@TK2MSFTN GP12.phx.gbl...
>>>> Bernie,
>>>>
>>>> Tried it and this didn't make any difference. BAAHHH!
>>>> What I don't get is that the CommandBuilder object should create the
>>>> Insert command for me automatically based on the select query.
>>>> Why would Dot Net be getting it wrong with such a simple SQL
>>>> statement??
>>>> I've looked at other routines where I use the same technique and it
>>>> works and I can't see what is different between them?
>>>> --
>>>> Siv
>>>> Martley, Worcester, UK.
>>>>
>>>> "Bernie Yaeger" <berniey@cherwe llinc.com> wrote in message
>>>> news:u1VdPbd8EH A.2608@TK2MSFTN GP10.phx.gbl...
>>>> Hi Siv,
>>>>
>>>> I think your problem is with the dob column. You are sending it text
>>>> but it requires date data. Wrap it in "#" on both ends and see what
>>>> happens. Also, just to verify my belief, simply change it to now.date
>>>> to see if that is indeed the problem.
>>>>
>>>> HTH,
>>>>
>>>> Bernie Yaeger
>>>>
>>>> "Siv" <msnewsgroups@r emoveme.sivill. com> wrote in message
>>>> news:ekSZ7Nd8EH A.1524@TK2MSFTN GP09.phx.gbl...
>>>> Hi,
>>>> If I run the following:
>>>>
>>>> strSQL = "Select * FROM Clients;"
>>>>
>>>> da = New OleDb.OleDbData Adapter(strSQL, Conn) 'Create data
>>>> adapter
>>>> cb = New OleDb.OleDbComm andBuilder(da) 'Create command
>>>> builder using the datadapter
>>>> dt = New Data.DataTable
>>>> da.Fill(dt) 'pour in the data using the adapter
>>>>
>>>> rw = dt.NewRow
>>>> rw("ClientID") = GetNextIDNumber ("Clients")
>>>>
>>>> CurrentClientID = CLng(rw("Client ID")) 'Set
>>>> the currentClientID to this new client
>>>>
>>>> rw("RelatedClie ntLinkID") = CurrentRelatedC lientID 'Type is:
>>>> Long.
>>>> rw("IsPrimaryCl ient") = True
>>>> rw("Title") = txtTitleSelf.Te xt 'Type is: String.
>>>> rw("Forename") = txtForenameSelf .Text 'Type is:
>>>> String.
>>>> rw("OtherNames" ) = txtOtherNameSel f.Text 'Type is:
>>>> String.
>>>> rw("Surname") = txtSurnameSelf. Text 'Type is:
>>>> String.
>>>> rw("Relationshi pToPartner") = txtRelToPartner Self.Text 'Type is:
>>>> String.
>>>> rw("DOB") = txtDOBYYYYSelf. Text & "-" & txtDOBMMSelf.Te xt & "-" &
>>>> txtDOBDDSelf.Te xt 'Type is: Date.
>>>> rw("StateOfHeal th") = txtStateOfHealt hSelf.Text 'Type is:
>>>> String.
>>>> rw("SmokerYN") = chkSmokerSelf.C hecked 'Type is:
>>>> Boolean.
>>>> rw("Notes") = txtNotesSelf.Te xt 'Type
>>>> is: String.
>>>> rw("DateCreated ") = Now
>>>> 'Type is: Date.
>>>> rw("User") = CurrentUser 'Type is String
>>>> dt.Rows.Add(rw) 'Add the new row
>>>> da.Update(dt) 'Send the update to the actual database using
>>>> the adapter
>>>>
>>>> At the da.Update(dt) line I det an exception thrown: "Syntax error in
>>>> INSERT INTO statement."
>>>>
>>>> I have other code that uses the same technique and I don't get an error
>>>> at all. I have tried changing the strSQL text so that it is more
>>>> complex and it makes no difference.
>>>> If anyone can see the glaring mistake that I am making please put me
>>>> out of my misery!
>>>>
>>>> Siv
>>>> Martley, Worcester, UK.
>>>>
>>>
>>>[/color]
>>
>>[/color]
>
>[/color]
Comment