VB.net working with sql string does not work, help...

  • Thread starter Thread starter April
  • Start date Start date
A

April

Hope someone can help me
The SQL string i need to use does not work, Who can help me....
Thanks in advance





Dim strConn As String
Dim strSQL As String
Dim dsArtikel As New DataSet("DataSetName")
'Dim strconn As OleDbConnection

strConn = "Provider = Microsoft.Jet.OLEDB.4.0;"
strConn &= "Data Source = " & Application.StartupPath &
"\BE_MasterControl.mdb;"

Dim conn As OleDbConnection = New OleDbConnection(strConn)
Dim sqlStr As String = "SELECT * FROM tblProducten"
THIS IS WORKING
REM Dim sqlStr As String = "SELECT * FROM tblProducten where
OnzeRef = A4214" THIS DOES NOT WORK

' Create data adapter object
Dim daArtikel As OleDbDataAdapter = New OleDbDataAdapter(sqlStr,
conn)

' Create a dataset object and fill with data using data adapter's
Fill method
Dim ds As DataSet = New DataSet
daArtikel.Fill(dsArtikel, "tblProducten")

Me.DataGrid1.DataSource = dsArtikel
Me.DataGrid1.DataMember = "tblProducten"
 
REM Dim sqlStr As String = "SELECT * FROM tblProducten where OnzeRef =
A4214" THIS DOES NOT WORK

Presumably, the tblProdukten.OnzeRef field is not numeric? Therefore:

Dim sqlStr As String = "SELECT * FROM tblProducten where OnzeRef = 'A4214'"
 
Hi as Mark and Cor suggested, it most likely has to do with the ' ', but the
thing I do when I write sql string is first try them out in my database
program (sql server, access) with values I'm sure will return something.
Maybe this can help you in the future.

Greetz Peter
 
Ok this is working, many thanks for your help
Stupid of my not to think or try this ...

Best Regards
Marc.
 
Another question,

And if I want to use a variable like "strOnzeRef"

Dim sqlStr As String = "SELECT * FROM tblProducten where OnzeRef = 'A4214'"
Dim sqlStr As String = "SELECT * FROM tblProducten where OnzeRef =
""'" & strOnzeRef & "'"""

I tried differents but not working
 
Dim sqlStr as String = "Select * from tblProductenwhere OnzeRef = '" &
strOnzeRef & "'"
(Just to be sure you get it right the quote sequence in words OnzeRef =
single double & strOnzeRef & double single souble)

hth Greetz Peter

should do the trick
 
Dim sqlStr As String = "SELECT * FROM tblProducten where OnzeRef = '" &
strOnzeRef &"'"

I think this would work.
 
Back
Top