Hi All,

My wife is into the slimming world diet and has magazines with her favorite diets marked, so I decided to write her a desktop application so she can save all her recepies and tidy all those magazines.

So please see my code for my breakfast form below

Imports System.Data.SqlClient
Public Class Breakfast

    Dim conn As SqlConnection
    Dim breakfast As SqlDataAdapter
    Dim dsbreakfast As DataSet

    Private Sub Breakfast_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load

        Try
            conn = New SqlConnection("Data Source=JOHN-ELLIS-PC;Initial Catalog=SlimmingWorld;Integrated Security=True")
            dsbreakfast = New DataSet
            breakfast = New SqlDataAdapter("SELECT RedorGreen,Name,Ingredients,Sins,FROM Breakfast", conn)
            Dim cmdBuilder As SqlCommandBuilder = New SqlCommandBuilder(breakfast)
            breakfast.Fill(dsbreakfast, "breakfast")
            DataGridView1.DataSource = dsbreakfast.Tables("Breakfast")
        Catch ex As Exception
            MsgBox(ex.Message)
        End Try


    End Sub

    Private Sub SaveToolStripButton_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles SaveToolStripButton.Click
        breakfast.Update(dsbreakfast, "breakfast")
    End Sub
End Class

I am getting an error when I run the program that says "syntax error near the keyword FROM."

Please see below my sql database I wrote

USE [master]
GO
CREATE DATABASE SlimmingWorld
GO
USE SlimmingWorld
GO

CREATE TABLE [dbo].[Breakfast](
[RedorGreen][nvarchar](50) NULL,
[Name][nvarchar](50) NULL,
[Ingredients][nvarchar](50) NULL,
[Sins][nvarchar](50) NULL)

I have spent ages looking for the problem and I just can't see it, can anyone help.

Thanks

John

You have a comma directly before FROM in your SQL statement. You need to remove that.

commented: much appreciated, thanks +3

Take out the comma in ",FROM Breakfast".

Thank you, both of you, I normally use the "add data source wizard" but you can do so much more by actually writing the code, but the tiniest little thing can trip you up.

It supprises me that I had a syntax error and vb did not show an error in design time.

Thanks again for your help.

John

It's not a VB syntax error. As far as VB is concerned it is just a character string. The error doesn't actually get detected until SQL Server tries to parse and execute the string as a SQL command.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.