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

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"
 
M

Mark Rae

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'"
 
P

Peter Proost

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
 
A

April

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

Best Regards
Marc.
 
A

April

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
 
P

Peter Proost

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
 
G

Guest

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

I think this would work.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top