简体   繁体   中英

Error when trying to insert values into a SQL Server CE database

I am having trouble inserting values into my Account table that's in a SQL Server Compact Edition database. I keep on getting an error that states

There was an error parsing the query. [Token line number=1, Token line offset =62, Token in error = s].

This seems to be a common error with SQL Server CE, but everything I have tried doesn't seem to work. Here is the code:

Public Sub addPlan(ByVal planname As String, ByVal plannumber As String)

    Dim strSql As String = (String.Format("INSERT INTO [Account] (plan_name, plan_number) VALUES (N'{0},N'{1})", Trim(planname), Trim(plannumber)))

    Try

        Using cmdAdd As New SqlCeCommand(strSql, conn)
            cmdAdd.ExecuteNonQuery()
        End Using

    Catch ex As Exception
        MessageBox.Show(ex.ToString)

    Finally
        displayPlandt()
    End Try

End Sub

Public Sub displayPlandt()

    Dim strSql As String = "SELECT * From Account"

    Using dtadapter As New SqlCeDataAdapter(strSql, conn)

        Dim dt As New DataTable
        dtadapter.Fill(dt)
        Form1.dgridplanview.DataSource = dt

    End Using

End Sub

Another question that I have is how I am updating the datatable on the form. I call this method in the finally portion of my try statement. However, I am re-querying the database and refilling the whole datatable every time I need to refresh it. Is there a way to do the same thing without refilling the whole datatable?

Thanks!

i think you miss end quotes.

Try this

Dim strSql As String = (String.Format("INSERT INTO [Account] (plan_name, plan_number) VALUES (N'{0}',N'{1}')", Trim(planname), Trim(plannumber)))

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM