does anyone has a sample code or it it possible to fix error in this code
I appreciate any advice

the error i get :
There was an error parsing the query. [ Token line number = 1,Token line offset = 13,Token in error = user ]
cmd.ExecuteNonQuery()

Imports System.Data.SqlServerCe
Public Class Form1
    Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
        ' Dim con As New OleDbConnection
        Dim con As SqlCeConnection = New SqlCeConnection("DataSource=C:\Program Files\Microsoft SQL Server Compact Edition\v3.5\samples\Northwind.sdf;Persist Security Info=False")


        Dim CmdStr As String = "insert into user (emp_name,category,city) values ('" & TextBox2.Text & "','" & TextBox3.Text & "','" & TextBox4.Text & "')"
        con.Open()
        Dim cmd As SqlCeCommand = New SqlCeCommand(CmdStr, con)
        cmd.ExecuteNonQuery()
        con.Close()
        MsgBox("Done")
    End Sub

   

    Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button2.Click
        Dim con As SqlCeConnection = New SqlCeConnection("DataSource=C:\Program Files\Microsoft SQL Server Compact Edition\v3.5\samples\Northwind.sdf;Persist Security Info=False")
       
        Dim Query2 As String = "select * from user"
        Dim DA As SqlCeDataAdapter, Ds As New DataSet, Dtb As New System.Data.DataTable

        con.Open()
        Da = New SqlCeDataAdapter(Query2, con)
        DA.Fill(Ds)
        con.Close()
        Dtb = Ds.Tables(0)
        DataGridView1.DataSource = Dtb

    End Sub

User is reserved keyword of MS-SQL.

Dim CmdStr As String = "insert into [user] (emp_name,category,city) values ('" & TextBox2.Text & "','" & TextBox3.Text & "','" & TextBox4.Text & "')"
Dim Query2 As String = "select * from [user]"

Thabk you so much . it works

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.