473,395 Members | 1,968 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,395 software developers and data experts.

Returning guid from inserted row in SQL server 2005

Hi All

Can someone help get the rowGUID value after an insert

I am using VB.net 2005 and SQL server Express 2005

The column GUID is an uniqueidentifier column with default value
(newsequentialid())

The following is my current function which is clumsy to say the least

I am sure there is a more elegant solution

Regards

Steve

----------------------------------------------------------------------------------------------------------
Public Function SaveParamDataGetGUID(ByVal mycmd As SqlCommand, ByVal
mytable As String) As Guid

Dim con As New SqlConnection, guid As Guid, sql As String = ""

Dim myint As Int16 = 0

Try

con.ConnectionString = connectionstring

con.Open()

mycmd.Connection = con

mycmd.ExecuteNonQuery()

sql = "select max(mykey) as maxkey from " & mytable

mycmd.CommandText = sql

myint = mycmd.ExecuteScalar

sql = "select guid from " & mytable & " where mykey = " & myint

mycmd.CommandText = sql

guid = mycmd.ExecuteScalar

Return guid

Catch ex As SqlException

mymsgbox(ex.Message)

Return Nothing

Finally

If Not IsNothing(mycmd) Then

mycmd.Dispose()

mycmd = Nothing

End If

If Not IsNothing(con) Then

con.Close()

con.Dispose()

con = Nothing

End If

End Try

End Function

---------------------------------------------------------------------------------------------------------------------------------------------------
Jul 22 '07 #1
3 5296
Can someone help get the rowGUID value after an insert

I am using VB.net 2005 and SQL server Express 2005

The column GUID is an uniqueidentifier column with default value
(newsequentialid())

The following is my current function which is clumsy to say the least

I am sure there is a more elegant solution

I prefer creating the GUID on the client.. This way you can insert a parent
and children in one transaction. No round trip perf issues are a good
thing.
Jul 22 '07 #2
"Robert" <no@spam.comwrote in
news:#s**************@TK2MSFTNGP04.phx.gbl:
I prefer creating the GUID on the client.. This way you can insert a
parent and children in one transaction. No round trip perf issues are
a good thing.
It depends on how you write your SQL statements - you could combine
everything into one statement to avoid the round trip.

Otherwise, using a DAL framework (LLBLGen Pro, NHibernate, Wilson OR/M,
etc) reduces your need to worry about such intracacies.
Jul 22 '07 #3
Hi Robert

How do you generate a Sequential GUID on the Client?

VB.net only has GUID class

Regards
Steve

"Robert" <no@spam.comwrote in message
news:%2****************@TK2MSFTNGP04.phx.gbl...
>
>Can someone help get the rowGUID value after an insert

I am using VB.net 2005 and SQL server Express 2005

The column GUID is an uniqueidentifier column with default value
(newsequentialid())

The following is my current function which is clumsy to say the least

I am sure there is a more elegant solution


I prefer creating the GUID on the client.. This way you can insert a
parent
and children in one transaction. No round trip perf issues are a good
thing.

Jul 22 '07 #4

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

Similar topics

1
by: Peter | last post by:
I've purchased VS.NET 2005 Standard and have tried to install SQL Server 2005 Express, but get the following error in the error log. Please could someone help me.... Microsoft SQL Server 2005...
2
by: R.A.M. | last post by:
Hello, I am learning SQL Server 2005. I need to create a trigger which increments number of book's publications: CREATE TRIGGER InsertPublication ON Publications AFTER INSERT AS BEGIN
9
by: billmiami2 | last post by:
I was playing around with the new SQL 2005 CLR functionality and remembered this discussion that I had with Erland Sommarskog concerning performance of scalar UDFs some time ago (See "Calling...
5
by: herman404 | last post by:
Hi everyone, I have some code that we need to migrate to SQL Server 2005 from 2000, and I have a webpage that upon viewing, fires a query to the SQL server using ISS and ISAPI. The result set is...
4
by: phil2phil | last post by:
hi, i have a column of type ntext in the db, we're using that to allow users to store essays they can enter. problem is when i'm running a select on the ntext column, data seems to be getting cut...
3
by: Lee T. Hawkins | last post by:
I am having a number of problems over the last two full days trying to get an ASP.NET 2.0 application to connect to a SQL Server 2005 database... First off, I built this application w/ Visual...
1
by: Zeljko Bilandzija | last post by:
Hello! I have a problem, and I looking for help if someone can handle this. I use asp.net 2.0, and I create web site which support users from internet (Web Site Administration Tool) and with...
2
by: Dinesh | last post by:
Hi experts, I am working on SQL Server 2005. Now i have to write a query which will extract some information from a table. My main table is having few columns supose 3 columns. EmpID ...
0
by: tskmjk | last post by:
Hi all, I am developing an application which reads an excel file which has the following records and inserts into a table in SQL SERVER 2005 database . Data: Product ...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
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
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
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
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
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
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...

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.