Line 1: Incorrect syntax near '1'.

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

I just use DataSet to bind DataSetGrid and display from SQL DB.
when starting run in Visual Studio 2005, get "Line 1: Incorrect syntax near
'1'" error message from below fill line,

objDataAdapter.Fill(objDataSet, "mindata")


any help is greatly appriciated.
 
The error refers to a syntax error in the SQL query you are using to get
the data. What does the SQL query look like?
 
it is

objDataAdapter.SelectCommand.CommandText = _
"Select Parameter, Average, Units from mindata"

Thanks
 
the whole program is :

Imports System.Data
Imports System.Data.SqlClient


Public Class GreeneCTControlRoom
Dim objConnection As New SqlConnection _
("Server=server1; database=db1;user id=sa;password=whatever")
Dim objDataAdapter As New SqlDataAdapter()
Dim objDataSet As New DataSet()


Private Sub GreeneCTControlRoom_Load(ByVal sender As Object, ByVal e As
System.EventArgs) Handles Me.Load
objDataAdapter.SelectCommand = New SqlCommand()
objDataAdapter.SelectCommand.Connection = objConnection
objDataAdapter.SelectCommand.CommandText = _
"Select Parameter, Average, Units from mindata"
objDataAdapter.SelectCommand.CommandText = CommandType.Text

objConnection.Open()
objDataAdapter.Fill(objDataSet, "mindata")
objConnection.Close()

grdControlRoom.AutoGenerateColumns = True
grdControlRoom.DataSource = objDataSet
grdControlRoom.DataMember = "mindata"

objDataAdapter = Nothing
objConnection = Nothing

End Sub


End Class
 
There is nothing obvious that could possibly cause that error message
using that query.

Is there something less obvious going on? Is mindata a view? Do you have
any triggers in the database?
 
I figure out, I type something wrong, it should be

objDataAdapter.SelectCommand.CommandType = CommandType.Text

then work

Thanks
 
Yes, now I see it. The CommandType.Text value is automatically converted
to the number 1, and then automatically converted to the string "1".

You should use Option Strict On to avoid these unintentional conversions.
 
Back
Top