EDN Admin
Well-known member
Can anyone tell me what is wrong with this syntax. I want to run a SQL query from text in a label.<SQL>
SELECT
Identifier,
UserName,
UserPassword,
UserTimer
FROM tblContacts
WHERE UserName = "" + lblName.Text + "", con);
</SQL>
I get this error mesage
Syntax error (missing operator) in query expression UserName = "" + lblName.Text + "", con).
Thanks Nige
ps I have a label called lblName in the same windows form. So the whole of my button click event looks like.Private Sub Button5_Click_1(sender As Object, e As EventArgs) Handles Button5.Click
Dim Builder As New OleDb.OleDbConnectionStringBuilder With
{
.Provider = "Microsoft.ACE.OLEDB.12.0",
.DataSource = IO.Path.Combine(Application.StartupPath, "C:UsersNigeDocumentsVisual Studio 2012ProjectsMS_Access_SimplePasswordbinDebugDatabase1.mdb"),
.PersistSecurityInfo = True
}
lblName.Text = LoginForm.txtUserName.Text
If lblName.Text = LoginForm.txtUserName.Text Then
Builder.Add("Jet OLEDBatabase Password", "password")
Using con As New OleDb.OleDbConnection With {.ConnectionString = Builder.ConnectionString}
Using cmd As New OleDb.OleDbCommand With
{
.Connection = con,
.CommandText =
<SQL>
SELECT
Identifier,
UserName,
UserPassword,
UserTimer
FROM tblContacts
WHERE UserName = "" + lblName.Text + "", con);
</SQL>.Value
}
con.Open()
Dim Reader As OleDb.OleDbDataReader = cmd.ExecuteReader
If Reader.HasRows Then
Reader.Read()
TextBox1.Text = Reader.GetInt32(0).ToString
TextBox2.Text = Reader.GetString(1)
TextBox3.Text = Reader.GetString(2)
TextBox4.Text = Reader.GetString(3)
End If
End Using
End Using
End If
End Sub
View the full article
SELECT
Identifier,
UserName,
UserPassword,
UserTimer
FROM tblContacts
WHERE UserName = "" + lblName.Text + "", con);
</SQL>
I get this error mesage
Syntax error (missing operator) in query expression UserName = "" + lblName.Text + "", con).
Thanks Nige
ps I have a label called lblName in the same windows form. So the whole of my button click event looks like.Private Sub Button5_Click_1(sender As Object, e As EventArgs) Handles Button5.Click
Dim Builder As New OleDb.OleDbConnectionStringBuilder With
{
.Provider = "Microsoft.ACE.OLEDB.12.0",
.DataSource = IO.Path.Combine(Application.StartupPath, "C:UsersNigeDocumentsVisual Studio 2012ProjectsMS_Access_SimplePasswordbinDebugDatabase1.mdb"),
.PersistSecurityInfo = True
}
lblName.Text = LoginForm.txtUserName.Text
If lblName.Text = LoginForm.txtUserName.Text Then
Builder.Add("Jet OLEDBatabase Password", "password")
Using con As New OleDb.OleDbConnection With {.ConnectionString = Builder.ConnectionString}
Using cmd As New OleDb.OleDbCommand With
{
.Connection = con,
.CommandText =
<SQL>
SELECT
Identifier,
UserName,
UserPassword,
UserTimer
FROM tblContacts
WHERE UserName = "" + lblName.Text + "", con);
</SQL>.Value
}
con.Open()
Dim Reader As OleDb.OleDbDataReader = cmd.ExecuteReader
If Reader.HasRows Then
Reader.Read()
TextBox1.Text = Reader.GetInt32(0).ToString
TextBox2.Text = Reader.GetString(1)
TextBox3.Text = Reader.GetString(2)
TextBox4.Text = Reader.GetString(3)
End If
End Using
End Using
End If
End Sub
View the full article