473,662 Members | 2,536 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Guid handling

Hi

I have a drop down list on my page that lists some items returned from a
database. Each item has its GUID (or uniqueidentifie r). I have to (in code
behind of the page) read this GUID, to hand it over to a query (stored
procedure) that takes the GUID and looks for some data in a specific table.
I don't know have to hand it to the query as GUID.

SqlCommand myCommand = new SqlCommand();
myCommand.Conne ction = myConnection;

myCommand.Comma ndText = "dbo.tbh_GetBou ndIdentifier";
myCommand.Comma ndType = CommandType.Sto redProcedure;

string BoundID =
DropDownList4.S electedItem.Val ue.ToString();

SqlParameter myParameter1 = new SqlParameter();
myParameter1.Pa rameterName = "@BoundID";
myParameter1.Sq lDbType = SqlDbType.Uniqu eIdentifier;
myParameter1.Va lue = BoundID;

SqlParameter myParameter2 = new SqlParameter();
myParameter2.Pa rameterName = "@BoundIdentifi er";
myParameter2.Sq lDbType = SqlDbType.Char;
myParameter2.Di rection = ParameterDirect ion.Output;

myCommand.Param eters.Add(myPar ameter1);
myCommand.Param eters.Add(myPar ameter2);

myConnection.Op en();

SqlDataReader myReader = myCommand.Execu teReader();
WIth the code above I get the following error: "Failed to convert parameter
value from a String to a Guid" when trying to execute the command
myCommand.Execu teReader();. How can I handle (or convert) the GUID so it is
handed as GUID and not as a string?
Jun 27 '08 #1
1 1375
Found solution myself:

Guid BoundID = new Guid(DropDownLi st4.SelectedIte m.Value.ToStrin g());
Regards
"Igor" <ig***@live.com wrote in message
news:E5******** *************** ***********@mic rosoft.com...
Hi

I have a drop down list on my page that lists some items returned from a
database. Each item has its GUID (or uniqueidentifie r). I have to (in code
behind of the page) read this GUID, to hand it over to a query (stored
procedure) that takes the GUID and looks for some data in a specific
table. I don't know have to hand it to the query as GUID.

SqlCommand myCommand = new SqlCommand();
myCommand.Conne ction = myConnection;

myCommand.Comma ndText = "dbo.tbh_GetBou ndIdentifier";
myCommand.Comma ndType = CommandType.Sto redProcedure;

string BoundID =
DropDownList4.S electedItem.Val ue.ToString();

SqlParameter myParameter1 = new SqlParameter();
myParameter1.Pa rameterName = "@BoundID";
myParameter1.Sq lDbType = SqlDbType.Uniqu eIdentifier;
myParameter1.Va lue = BoundID;

SqlParameter myParameter2 = new SqlParameter();
myParameter2.Pa rameterName = "@BoundIdentifi er";
myParameter2.Sq lDbType = SqlDbType.Char;
myParameter2.Di rection = ParameterDirect ion.Output;

myCommand.Param eters.Add(myPar ameter1);
myCommand.Param eters.Add(myPar ameter2);

myConnection.Op en();

SqlDataReader myReader = myCommand.Execu teReader();
WIth the code above I get the following error: "Failed to convert
parameter value from a String to a Guid" when trying to execute the
command myCommand.Execu teReader();. How can I handle (or convert) the GUID
so it is handed as GUID and not as a string?

Jun 27 '08 #2

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

Similar topics

4
15635
by: Louis Frolio | last post by:
Greetings All, I have read many upon many articles here regarding GUID data types and uniqueness. There have been many opinions regarding the effectiveness of GUID's and when they should/should not be used. However, every article strongly implies, if it does not state it outright, that GUID's are always unique. My question is this, what happens if you have a database that uses GUID's and the NIC is changed out on the box? From what I...
10
3291
by: Frits JK | last post by:
Hallo, I have to write a GUID to the register but I don't know to convert to hexadecimal. I have tried several things but I am shore that line 5 and 6 are not correct. //-------------------------------------------------------------------------- ---------- if (RegCreateKeyEx(HKEY_LOCAL_MACHINE,
9
34831
by: Rene | last post by:
I am using the Guid.Empty value ("00000000-0000-0000-0000-000000000000") to represent a special meaning. The problem is that I don't know if there is a chance that a command like "Guid.NewGuid()"would generate a Guid.Empty value could this be possible or is the "00000000-0000-0000-0000-000000000000" Guid reserved or something like that? Thank you.
14
14256
by: Nak | last post by:
Hi there, Does anyone know how I would get the value of the assembly GUID in code from within the same application? Thanks in advance. Nick. -- /\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\ Slow internet connection?
5
6329
by: rcolby | last post by:
Evening, Wondering if someone can point me in the right direction, on how I would compare a system.guid with a system.byte. system.guid (pulled from sql server table with a data type of uniqueidentifier, originally taken from objectGUID from active directory domain)
5
13706
by: George | last post by:
I want to create a unique id for each of a set of objects. These ids may be generated on multiple machines simultaneously and must all be different to each other. There are an undefined number of machines involved (1 to dozens) and an indeterminate number of objects (many to very many on each machine). My best guess for a solution would be to use a GUID (all the machines have an ethernet connection so a GUID generated on any of them...
1
4109
by: Wolf | last post by:
Hi I am trying to set a property(PartyHomeAddressID) = to a guid in a ini file. But everytime when the ini file has an empty guid it breaks with an error tellin me a guid is 32 char long with 4 dashes. client.PartyHomeAddressID = new Guid(contact.Substring(1542, 36).Trim());
5
6493
by: Michael Primeaux | last post by:
I have a simple .NET 2.0 web service created with VS.NET 2005 with a single web method with the following signature: void HelloWorld(Guid parameter1); When calling this method I receive the following error: System.IndexOutOfRangeException: Index was outside the bounds of the array. at System.Web.Services.Protocols.HttpServerType..ctor(Type type) at System.Web.Services.Protocols.HttpServerProtocol.Initialize()
2
16178
by: Troll | last post by:
Windows XP Pro VS 2005 & C# (I'm fairly new to C# but have doing VB.Net going on 2yrs and VB6 for 5yrs.) I'm using C# to build a custom RSS generator. I'm having trouble building the guid element for each item node in my feed. Some items do not have the "link" node because the description element is the content. So using the "link" as the guid will not work in my case, as some sites suggest and as feedvalidator.org complains when I do not...
0
8432
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
8857
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, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
1
8546
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
7367
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...
1
6186
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
5654
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
4180
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...
2
1993
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
2
1752
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.