I think bob is a string value, so your statement should look like this,

INSERT INTO [primary] values('bob')


On Mon, Mar 8, 2010 at 11:20 AM, [email protected] <[email protected]>wrote:

> Hi,
>
> When I run the code below I receive an error message of Incorrect
> syntax near the keyword 'primary' after executenonquery is run.
> Primary being my table name for my database. I've tried to simplify
> this code down as much as I can, but I can't seem to fix the syntax
> issue. If you see what I did wrong please let me know, I'm at whits
> end. As for my DB table, all I have is one field which is set to text,
> so the data being inserted should work fine. This isn't being rejected
> by the SQL server itself since nothing shows in the logs. Database
> connection is functioning.
>
> Imports Microsoft.VisualBasic
> Imports System.Data
> Imports System.Data.OleDb
> Imports System.Web
> Imports System.Data.SqlClient
>
> Public Class DataAccess
>    Public Sub MyClickevent(ByVal Sender As Object, ByVal E As
> EventArgs)
>        Dim currentContext As System.Web.HttpContext =
> System.Web.HttpContext.Current
>        Dim conn As New SqlConnection()
>        conn.ConnectionString = "Data Source=localhost
> \sqlexpress;Initial Catalog=corporations;Persist Security
> Info=True;User ID=corpuser;Password=secretpassword"
>        Dim rowCount As Integer
>        Dim previousConnectionState As ConnectionState
>        Dim strSQL As String = "INSERT INTO primary values bob"
>        previousConnectionState = conn.State
>        Try
>            If conn.State = ConnectionState.Closed Then
>                conn.Open()
>
>            End If
>            Dim dbComm As New SqlCommand(strSQL, conn)
>            rowCount = dbComm.ExecuteNonQuery()
>            currentContext.Response.Write("A new record has been
> added: " & rowCount)
>            currentContext.Response.End()
>        Catch ex As Exception
>            currentContext.Response.Write(ex.Message)
>            currentContext.Response.Write(ex.StackTrace)
>            currentContext.Response.End()
>        Finally
>            If previousConnectionState = ConnectionState.Closed Then
>                conn.Close()
>            End If
>        End Try
>
>    End Sub
>
> End Class
>
>
>

Reply via email to