Whenever I run my code, I get the following error: " Line 1: Incorrect syntax near ')' "
I can't fgure out what I am doing wrong. I have modified my code following examples I found in books or web sites and each time, ths is the error I get.
Here's the code:
Private Sub GetTotoExt(ByVal PrmValue As Object)
Dim StrConn As String = My.Settings.SignsConnectString
Dim CmdSql As SqlClient.SqlCommand
Dim StrSql As String
Dim NbRows As Integer
CmdSql = New SqlClient.SqlCommand
CmdSql.Connection = New SqlClient.SqlConnection(StrConn)
StrSql = "SELECT COUNT(*) AS count_toto_ext FROM(toto_ext) WHERE (No = @totokey)"
CmdSql.CommandText = StrSql
With CmdSql.Parameters
.Clear()
.AddWithValue("@totokey", PrmValue.text)
End With
If (CmdSql.Connection.State = ConnectionState.Closed) Then
CmdSql.Connection.Open()
End If
NbRows = CmdSql.ExecuteScalar() ' this line generates the error.
End Sub
Thanks!
Claude.

I get "Line 1: Incorrect syntax near ')'." when using SqlClient ExecuteScalar
majorobvious
StrSql = "SELECT COUNT AS count_toto_ext FROM toto_ext WHERE (No = @totokey)"
Try the following. When escaping column names or table names you would usually use a [] not a () and you woudl only usually use it if you were required to do it.
Hope this helps.
harendra
Thank you Marc!
Yes, it did solve my problem. The error is gone.
Claude.