Is this an UPDATE in vbnet ? please help

  • Thread starter Thread starter Marc
  • Start date Start date
M

Marc

Hi

a strange problem, probably a bug in vbnet i think,


Working with vbnet visualStudio 2005
Windows forms, controls textboxes (not a datagridview)


Working mith the same query
Update works fine in SqlConnection
BUT fails with OleDbConnection specialy if there are amty textboxes

Am I doing something wrong or is this a bug!! how to work around


Sub UpdateData

IntAdresId = CInt(Me.txtAdresID.Text)
Dim strSQL As String = "UPDATE tblAdressen " & _
" SET Naam = '" & Me.txtNaam.Text.ToString & "' ," & _
" Straat = '" & Me.txtStraat.Text.ToString & "' ," & _
" Postcode= '" & Me.cboPostcode.Text.ToString & "' ," & _
" Plaats = '" & Me.cboPlaats.Text.ToString & "' ," & _
" Land = '" & Me.cboLand.Text.ToString & "' ," & _
" Landcode ='" & Me.txtLandcode.Text.ToString & "'," & _
" BtwNr = '" & Me.txtBtwNr.Text.ToString & "'," & _
" BtwCode= '" & Me.txtBtwCode.Text.ToString & "'," & _
" Tel1 = '" & Me.txtTel1.Text.ToString & "'," & _
" Gsm = '" & Me.txtGsm.Text.ToString & "'," & _
" Fax = '" & Me.txtFax.Text.ToString & "'," & _
" Url = '" & Me.txtUrl.Text.ToString & "' ," & _
" Korting = " & intKorting.ToString & " ," & _
" Toelichting = '" & Me.txtToelichting.Text.ToString & "' ,"
& _
" Activiteit = '" & Me.txtActiviteit.Text.ToString & "' ," &
_
" LocMap = '" & Me.txtLocMap.Text.ToString & "' ," & _
" BetaalTerm = " & Me.cboBetaalterm.Text.ToString & " ," & _
" Email = '" & Me.txtEmail.Text & "'" & _
" WHERE tblAdressen.AdresID = " & IntAdresId.ToString
'= = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = =
= = = =


'*** IF WORKING WIT MSSQL EXPRESS AS BACKEND


Dim objConn As New SqlConnection(strConnString)
objConn.Open()

' Console.WriteLine(sSQL)
Dim objCmd As New SqlCommand(strSQL, objConn)
objCmd.ExecuteNonQuery()
objConn.Close()



'*** IF WORKING WITH MSACCESS AS BACKEND

Dim objConn As New OleDbConnection(strConnString)
objConn.Open()
Dim objCmd As New OleDbCommand(strSQL, objConn)
objCmd.ExecuteNonQuery()
objConn.Close()
End Sub



Many thanks in advance,
Marc.
 
Marc said:
Working mith the same query
Update works fine in SqlConnection
BUT fails with OleDbConnection specialy if there are amty textboxes

"fails" means what exactly? What is the exception message? Maybe the
AllowZeroLength property of the field in the Access database is set to
False.
Am I doing something wrong or is this a bug!! how to work around


Sub UpdateData

IntAdresId = CInt(Me.txtAdresID.Text)
Dim strSQL As String = "UPDATE tblAdressen " & _
" SET Naam = '" & Me.txtNaam.Text.ToString & "' ," & _

It's strongly recommended to use the OleDb/SqlCommand's Parameters property
instead of concatenating the SQL string.

BTW, microsoft.public.de.vb.datenbank is the German group for VB6 database
questions.


Armin
 
Hi Armin,


Thanks for answering,

Even when using the OledbCommand's Parameters property, if there is one
empty textbox i get an error and data will not be updated!



Marc.
 
I see, that will be the only shoise if using Access as backend...
If using Msql express there is no problem on this...

anyway thanks for answering
Marc.
 
Yes i know, I was just trying to make an application multifunctional to have
a choice using Access or MsSQL, so now i know if so i have to make changes
in my code if needed to use Access.

Many thanks for your replys,
Marc.
 
BTW, microsoft.public.de.vb.datenbank is the German group for VB6 database
questions.
Armin,

That was not an easy one for me to understand
However, Datenbank means nothing in Dutch

(I got it at the end)

:-)

Cor
 
Back
Top