Results 1 to 8 of 8

Thread: Incorrect syntax near '='.

  1. #1
    JohnDW is offline VB.NET Forum Enthusiast
    .NET Framework
    .NET 3.5
    Join Date
    Jun 2012
    Location
    Antwerp, Belgium
    Posts
    58
    Reputation
    15

    Incorrect syntax near '='.

    Dear members,

    I'm working on a form with a datagridview that is getting filled
    with the 'txtKlantnummer_Changed' method.
    With closing the form i've got an sqlexception with debugging.
    the message: Incorrect syntax near '='.

    How it works:
    in the form is a textbox with a number that is getting filled.
    With the change of that number ("txtKlantnummer_Changed ') a datagridview get filled.
    This works, but when closing of the form, the error comes when executing
    Da.Fill(TaKlant).

    Code:
    PrivateSub txtKlantnummer_TextChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles txtKlantnummer.TextChanged
    Dim Cn AsSqlConnection
    Cn = NewSqlConnection(Cnst)
    Dim Cmd AsSqlCommand = Cn.CreateCommand
    Cmd.CommandText = "Select Klant.Klantnummer, Klant.Naamvoornaam, Klant.Adres From Klant Where Klant.Klantnummer=" & txtKlantnummer.Text
    Da = NewSqlDataAdapter(Cmd)
    Dim TaKlant AsNewDataTable
    Da.Fill(TaKlant)
    DGV1.DataSource = TaKlant
    EndSub
    
    


    What can be the problem?

    Grtz,

    John
    Last edited by JohnDW; 07-08-2012 at 5:58 AM.

  2. #2
    Lotok is offline VB.NET Forum Genius
    .NET Framework
    .NET 4.0
    Join Date
    Jan 2012
    Location
    Scotland
    Posts
    193
    Reputation
    22
    You haven't set command type, not sure but think it defaults to stored procedure.

    Sent from my XT910 using Tapatalk 2

  3. #3
    JohnDW is offline VB.NET Forum Enthusiast
    .NET Framework
    .NET 3.5
    Join Date
    Jun 2012
    Location
    Antwerp, Belgium
    Posts
    58
    Reputation
    15
    I've worked around it with:
    If txtKlantnummer.Text = ""Then
    Exit Sub

    Do ya have any info about set command type and that it defaults to stored proc?
    (a url maybe?)


    Grtz,

    John

  4. #4
    Lotok is offline VB.NET Forum Genius
    .NET Framework
    .NET 4.0
    Join Date
    Jan 2012
    Location
    Scotland
    Posts
    193
    Reputation
    22
    http://msdn.microsoft.com/en-us/libr...mmandtype.aspx

    Doesn't mention a default so I could be wrong, want sure.

    Use some validation to make sure a number goes in the text box

    Sent from my XT910 using Tapatalk 2

  5. #5
    jacky.goy's Avatar
    jacky.goy is offline VB.NET Forum Enthusiast
    .NET Framework
    .NET 4.0
    Join Date
    Sep 2006
    Posts
    35
    Reputation
    84
    try add below 2 line before commandtext
    cmd.CommandType = CommandType.Text
    cmd.Connection = con

    then change your command text as below

    Cmd.CommandText = "Select Klant.Klantnummer, Klant.Naamvoornaam, Klant.Adres From Klant Where Klant.Klantnummer =' txtKlantnummer.Text "'"
    -------------------------------------------------
    Best Regards,
    Jacky Goy

  6. #6
    Sparrow is offline VB.NET Forum Newbie
    .NET Framework
    .NET 3.5
    Join Date
    Jul 2012
    Posts
    6
    Reputation
    0
    Cmd.CommandText = "SELECT Klant.Klantnummer, Klant.Naamvoornaam, Klant.Adres From Klant WHERE Klant.Klantnummer='" & txtKlantnummer.Text & "'"

  7. #7
    Sparrow is offline VB.NET Forum Newbie
    .NET Framework
    .NET 3.5
    Join Date
    Jul 2012
    Posts
    6
    Reputation
    0
    or you can say:


    Cmd.CommandText = "SELECT Klantnummer, Naamvoornaam, Adres FROM Klant WHERE Klantnummer='" & txtKlantnummer.Text & "'"

  8. #8
    Sparrow is offline VB.NET Forum Newbie
    .NET Framework
    .NET 3.5
    Join Date
    Jul 2012
    Posts
    6
    Reputation
    0
    When you want to fill your data grid view or data set you can say:

    Dim Sql as string
    Sql = "SELECT Klantnummer, Naamvoornaam, Adres FROM Klant WHERE Klantnummer='" & txtKlantnummer.Text & "'"
    Dim Taklant As New DataTable = sqlfunctions.filldatatablr(Sql)

    'Create a module named sqlfunction and put this on it:

    Public Function filldatatable(ByVal sql As String) As DataTable
    Cursor.Current = Cursors.WaitCursor
    Dim cs As String
    cs = "Connection string goes here"
    Dim con As New MySqlConnection(cs)
    Dim ds As New DataTable
    Dim da As New MySqlDataAdapter




    Try
    Try


    con.Open()
    da = New MySqlDataAdapter(sql, con)
    da.Fill(ds)
    filldatatable = ds
    con.Close()
    Cursor.Current = Cursors.Default
    Return filldatatable
    Catch ex As Exception
    MessageBox.Show("Unable to communicate with sql server", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error)
    MsgBox(ex.ToString)
    End Try
    Catch myerror As MySqlException
    MessageBox.Show("Error Updating Databse : " & myerror.Message)


    End Try
    Cursor.Current = Cursors.Default


    End Function

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Harvest time tracking