Reputation: 3025
I am new to VB.net and creating an application so that user needs login username and password.
I am using a SQL Server Compact Edition database.
This is my code which works perfect:-
Imports System.Data.SqlClient
Imports System.Data.SqlServerCe
Public Class frm_edit_patient
Dim con As New SqlCeConnection
Try
Dim SQLquery As String
Dim da As SqlCeDataAdapter
Dim ds As New DataSet
Dim myConString As String = My.Settings.Database1ConnectionString
con.ConnectionString = myConString
MsgBox("Database is now open")
MessageBox.Show("connected")
Catch ex As Exception
MessageBox.Show(ex.ToString)
End Try
End Sub
The above code works fine and shows me connected
However when I add this piece of code
SQLquery = "SELECT id FROM user where username=John Doe"
da = New SqlCeDataAdapter(SQLquery, con)
da = New SqlCeDataAdapter(SQLquery, con)
da.Fill(ds, "db1")
It gives me this exception error:-
What does it mean? how to get the userid of that particular person?
Also if i just put the insert query in SQLquery
, will it work? As i have been doing this by watching few video tutorials, but further they don't have tutorials on this, also my book does not explains anything about Compact databases and as i am so far with this application dont want to switch...
Upvotes: 1
Views: 3138
Reputation: 216293
Put your username between single quotes and user is a reserved word in Sql Compact.
You need to enclose it in square brackets
SQLquery = "SELECT id FROM [user] where username='John Doe'"
Upvotes: 5
Reputation: 2448
There is an error in your SQL statement. Strings must be delimited using single quotes e.g.
SELECT id FROM user WHERE username = 'John Doe'
Upvotes: 1
Reputation: 5101
Add single quotes around your query.
SQLquery = "SELECT id FROM user where username='John Doe'"
Upvotes: 3