Home All Groups Group Topic Archive Search About

Line 1: Incorrect syntax near '1'.

Author
22 Jun 2006 7:15 PM
martin1
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.

Author
22 Jun 2006 7:45 PM
Göran Andersson
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?

martin1 wrote:
Show quoteHide quote
> 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.
Author
22 Jun 2006 8:12 PM
martin1
it is

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

Thanks

Show quoteHide quote
"Göran Andersson" wrote:

> 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?
>
> martin1 wrote:
> > 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.
>
Author
22 Jun 2006 8:14 PM
martin1
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


Show quoteHide quote
"Göran Andersson" wrote:

> 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?
>
> martin1 wrote:
> > 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.
>
Author
23 Jun 2006 11:09 AM
Göran Andersson
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?

martin1 wrote:
Show quoteHide quote
> 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
>
>
> "Göran Andersson" wrote:
>
>> 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?
>>
>> martin1 wrote:
>>> 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.
Author
23 Jun 2006 2:22 PM
martin1
I figure out, I type something wrong, it should be

objDataAdapter.SelectCommand.CommandType = CommandType.Text

then work

Thanks


Show quoteHide quote
"Göran Andersson" wrote:

> 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?
>
> martin1 wrote:
> > 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
> >
> >
> > "Göran Andersson" wrote:
> >
> >> 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?
> >>
> >> martin1 wrote:
> >>> 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.
>
Author
23 Jun 2006 5:16 PM
Göran Andersson
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.

martin1 wrote:
Show quoteHide quote
> I figure out, I type something wrong, it should be
>
> objDataAdapter.SelectCommand.CommandType = CommandType.Text
>
> then work
>
> Thanks
>
>
> "Göran Andersson" wrote:
>
>> 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?
>>
>> martin1 wrote:
>>> 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
>>>
>>>
>>> "Göran Andersson" wrote:
>>>
>>>> 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?
>>>>
>>>> martin1 wrote:
>>>>> 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.