473,657 Members | 2,287 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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 uniqueidentifie r column with default value
(newsequentiali d())

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 SaveParamDataGe tGUID(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.ConnectionS tring = connectionstrin g

con.Open()

mycmd.Connectio n = con

mycmd.ExecuteNo nQuery()

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

mycmd.CommandTe xt = sql

myint = mycmd.ExecuteSc alar

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

mycmd.CommandTe xt = sql

guid = mycmd.ExecuteSc alar

Return guid

Catch ex As SqlException

mymsgbox(ex.Mes sage)

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 5302
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 uniqueidentifie r column with default value
(newsequentiali d())

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.comwro te in
news:#s******** ******@TK2MSFTN GP04.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.comwro te in message
news:%2******** ********@TK2MSF TNGP04.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 uniqueidentifie r column with default value
(newsequential id())

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
6616
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 Express Edition x86: Component Microsoft SQL Server 2005 Express Edition x86 returned an unexpected value. ***EndOfSession***? Microsoft SQL Server 2005 Express Edition x86: Component Microsoft SQL Server 2005 Express Edition x86 returned an...
2
124933
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
3306
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 sp_oa* in function" in this newsgroup). In that discussion, Erland made the following comment about UDFs in SQL 2005: >>The good news is that in SQL 2005, Microsoft has addressed several of these issues, and the cost of a UDF is not as severe...
5
3208
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 formatted for display using XSLT. But since ISAPI is deprecated in SQL 2005, I was wondering how to migrate this. Thanks,
4
6417
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 off, isn't ntext suppose to hold a lot of data, we wanted to allow them in a min of 1500 chars, while everytime i do a select len(max (convert(nvarchar(2000), essaytext))) just to see the max we one had it's always 200.
3
3254
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 Studio 2005 SP1 and had it working perfectly on my Windows XP machine on SQL Server 2005 Express. I decided to publish this application to a test development server (with both the SQL and IIS servers on the same box) running on: Windows Server...
1
3003
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 that option i get database named ASPNETDB.MDF. When someone via page is creating account, database creates a new record in aspnet_users table. I made another table (table User_Data, columns UserID, Level, Points, ...), and i want that these data...
2
1910
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 Supervisor_ID Date_Of_Visit Now records are entering in this tabl. Date of visit is date of
0
1053
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 Version CustType ------------- ------------- -------------- Norton SystemWorks Basic Edition 2009 CS Norton 360 2 CS
0
8407
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, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
8319
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 effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
8739
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 tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
0
7347
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, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
0
5638
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
4171
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
4329
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
2739
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
1969
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

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.