473,396 Members | 1,877 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,396 software developers and data experts.

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

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.ConnectionStrin gs("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?

Apr 19 '06 #1
1 1687
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)
"dawg1998" <wr*******@gmail.com> wrote in message
news:11*********************@t31g2000cwb.googlegro ups.com...
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.ConnectionStrin gs("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?

Apr 19 '06 #2

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

4
by: Jacques Wentworth | last post by:
Hi I have the following problem. I have a SQL Server (2000) Stored Proc that with 4 parameter (one being @UnlockKey uniqueidentifier OUTPUT). I run it from Query Analyzer and the @Key parameter...
4
by: christopher.secord | last post by:
I have a table that contains articles (as in, newspaper articles, blog articles, whatever). I need to use a column of type uniqueidentifier because one of the requirements is that I be able to...
1
by: ing42 | last post by:
I have a problem with inserting records into table when an indexed view is based on it. Table has text field (without it there is no problem, but I need it). Here is a sample code: USE test GO...
3
by: teddysnips | last post by:
I need a trigger (well, I don't *need* one, but it would be optimal!) but I can't get it to work because it references ntext fields. Is there any alternative? I could write it in laborious code...
1
by: Vish | last post by:
Hi All, I am trying to insert a GUID generated in .NET into my SQL Server tables. I am inserting it into a column of type uniqueidentifier. The GUID generated by ..NET has lower case alphabets...
0
by: SA_DUDE | last post by:
For purposes of getting this to work, I have two tables in a SQL database. Car: idCars uniqueidentifier idColour uniqueidentifier RegNumber nchar(10) Colour: idColour uniqueidentifier
2
by: bob.speaking | last post by:
Hi at all, I'm trying to bulk insert a uniqueidentifier column from unicode file. In my file I have guid generated from c# application and they are formatted in this way (separated by "|") : ...
3
by: blazeboy | last post by:
Hello, I am using a SQL data source to insert records into a table. The table uses a GUID as the primary key (GoalEventID), and a GUID for a second field (GoalID) as a foreign key. When I call...
5
by: DotNetNewbie | last post by:
Hi, I am developing an application that has to scale and be very efficient, and I am using asp.net membership in my application. I set things up in my Users table (it has extra columns that I...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.