Error Inserting Uniqueidentifier Type with ASP.NET 2.0 and SQL Server 2005

D

dawg1998

I am attempting to create a record that has a uniqueidentifier
datatype. I am receiving the following error each time I attempt the
Insert:

Incorrect syntax near '-'

The following is the code I am using to execute the Insert:

Dim strSQL As String
Dim objConn As SqlConnection
Dim objCmd As SqlCommand

Dim idAccountID As Integer = 1
Dim UserID As String = ddlUserID.SelectedValue 'from a
dropdownlist
Dim idUserTypeID As Decimal = 1

strSQL = "INSERT INTO tblTable (idAccountID, UserID,
idUserTypeID) VALUES (" & idAccountID & ", '" & UserID & "', " &
idUserTypeID & ");"

Try
objConn = New
SqlConnection(ConfigurationManager.ConnectionStrings("connDatabaseConnection").ConnectionString)
objCmd = New SqlCommand(strSQL, objConn)
objConn.Open()
objCmd.ExecuteNonQuery()
Catch errError As Exception
lblSystemNotification.Text = errError.Message
Finally
objCmd.Dispose()
objConn.Dispose()
End Try

Any ideas how to Insert a uniqueidentifier value into a table without
getting this error?
 
B

bruce barker \(sqlwork.com\)

you do not specify which column is the uniqueidentifier. but this will work:

create table #foo (id uniqueidentifier)
insert #foo (id) values ('64A67F9A-9EF8-44D8-AA18-D6EDFD9ABFDA')

you are pobably missing the quotes. aslo you should be using parameters to
avoid sql injection.

-- bruce (sqlwork.com)
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,755
Messages
2,569,536
Members
45,007
Latest member
obedient dusk

Latest Threads

Top