vb.net - oledbCnn not connecting to Access Database -
i'm trying connect database. when simple select * works, moment add clause no longer works , says cannot connect. column name correct, , i'm sure there last name of lee in database. why work during simple select , not when there clause?
private sub button1_click(sender object, e eventargs) handles button1.click dim connetionstring string dim oledbcnn oledbconnection dim oledbadapter oledbdataadapter dim ds new dataset dim sql string dim integer connetionstring = "provider=microsoft.jet.oledb.4.0;data source=s:\reporting database.mdb;" sql = "select * [extract1] [extract1].[pi first name] = lee" oledbcnn = new oledbconnection(connetionstring) try oledbcnn.open() oledbadapter = new oledbdataadapter(sql, oledbcnn) oledbadapter.fill(ds) datagridview1.datasource = ds.tables(0) oledbadapter.dispose() oledbcnn.close() catch ex exception msgbox("can not open connection ! ") end try end sub
i guess should put lee
between quotes, like:
sql = "select * [extract1] [extract1].[pi first name] = 'lee'"
hint: use parameters avoid sql injection.
Comments
Post a Comment