Is this an UPDATE in vbnet ? please help

18/03/2009 - 16:13 von Marc | Report spam
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.
 

Lesen sie die antworten

#1 Armin Zingler
18/03/2009 - 16:53 | Warnen spam
Marc wrote:
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

Ähnliche fragen