How To Convert GUID GuidConverter ConvertTo Int32
Feb 15, 2007
Hi,
Can anyone help me figure out how to convert from type GUID to int32 format which will be the format to store in sqlserver database?
I have retrieved the UserId of a particular user in the current users profile (which is also a field in a row of data in table aspnet_Users) using this method:
MembershipUser user = Membership.GetUser(CreateUserWizard1.UserName);
and now would like to cast the following
user.ProviderUserKey type int32.
I thought the way to go was to use a GuidConverter by doing such as below by first assigning the user.ProviderUserKey in the _UserID variable and then calling:
TypeConverter converter = TypeDescriptor.GetConverter(_UserID);
Int32 newUserId = (Int32)converter.ConvertTo(_UserID, typeof(Int32));
But it blows up! any ideas?
thanks
~M
View 4 Replies
ADVERTISEMENT
Feb 21, 2008
hi
i am doing union of two queries and getting result. as we know datatypes should match
for query1 it has int 64
now how do i convert int32 to int 64. i am just putting dummy values in quey2 to match query1
View 1 Replies
View Related
Apr 15, 2012
i am trying to save data from unbound datagridview but i get the error " format exception unhandled- failed to convert parameter value to a int32" the following is my code:
Private Sub btnPlace_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnPlace.Click
' Modify the following code to correctly connect to your SQL Server.
Dim Connection As New SqlConnection("Server=.SQLEXPRESS;Initial Catalog=Store Management System;Integrated Security=SSPI ")
[code]...
View 1 Replies
View Related
Jun 20, 2007
i had writen a stored procedure for inserting vlaues frma form into sql but iam getting this error can any pls help me
Failed to convert parameter value from a String to a Int32
my stored procedureALTER PROCEDURE sp_addcustomer
(@customerid as int,
@fname as char(10),@lname as char(10) ,
@companyname as char(10),@email as nvarchar(50),
@address as char(10),@city as char(10),
@zip as char(10),@country as char(10),
@phone as nvarchar(50),@state as char(10)
)
ASinsert into customer(customerid ,fname ,lname ,companyname, email , address ,city,zip,country,phone,state)
values(@customerid ,@fname ,@lname ,@companyname,@email,@address,@city,@zip,@country,@phone,@state)
RETURN
CODE IN C# IS
SqlConnection cn = new SqlConnection(Session["conn"].ToString());
cn.Open();SqlCommand cmd = new SqlCommand();
cmd.Connection = cn;cmd.CommandType = CommandType.StoredProcedure;cmd.CommandText = "sp_addcustomer";
//SqlParameter p1, p2, p3, p4, p5, p6, p7, p8, p9, p10,p11;cmd.Parameters.Add(new SqlParameter("@customerid",SqlDbType.Int));
cmd.Parameters["@customerid"].Value =CustomerID.Text;cmd.Parameters.Add(new SqlParameter("@fname", SqlDbType.Char));
cmd.Parameters["@fname"].Value = fname.Text;cmd.Parameters.Add(new SqlParameter("@lname", SqlDbType.Char));
cmd.Parameters["@lname"].Value = lname.Text;cmd.Parameters.Add(new SqlParameter("@companyname", SqlDbType.Char));
cmd.Parameters["@companyname"].Value = companyname.Text;cmd.Parameters.Add(new SqlParameter("@email", SqlDbType.NVarChar));
cmd.Parameters["@email"].Value = email.Text;cmd.Parameters.Add(new SqlParameter("@address", SqlDbType.Char));
cmd.Parameters["@address"].Value = address.Text;cmd.Parameters.Add(new SqlParameter("@city", SqlDbType.Char));
cmd.Parameters["@city"].Value = city.Text;cmd.Parameters.Add(new SqlParameter("@zip", SqlDbType.NVarChar));
cmd.Parameters["@zip"].Value = zip.Text;cmd.Parameters.Add(new SqlParameter("@country", SqlDbType.Char));
cmd.Parameters["@country"].Value = Country.Text;cmd.Parameters.Add(new SqlParameter("@phone", SqlDbType.NVarChar));
cmd.Parameters["@phone"].Value = Phone.Text;cmd.Parameters.Add(new SqlParameter("@state", SqlDbType.Char));cmd.Parameters["@state"].Value = state.Text;
cmd.ExecuteNonQuery();
cn.Close();
Response.Redirect("main.aspx?st=Employee added successfully");
View 4 Replies
View Related
Jul 3, 2007
Hi all,I have setup my database that have 3 columns:1. Primary Key2. UserId (UniqueIdentifier, Guid I guess) - I set it up so I can insert the value from the Membership table (UserId) for some relationship.3. Another Foreign key with just an int. I tried to build a DAL, ran a test and received this error: "Failed to convert parameter value from a String to a Guid." Before I setup my UserId to be UniqueIdentifier and let it be just an Int, I don't have any problem retrieving data. Here is the SELECT query that I built with the DataSet:SELECT aspnet_Users.UserId, t_music.MUSIC_TITLEFROM t_user_viewedJOIN aspnet_Users ON aspnet_Users.UserId = t_user_viewed.UserId JOIN t_music ON t_music.MUSIC_PK = t_user_viewed.MUSIC_PK_FKWHERE aspnet_Users.UserId = @UserId Any help would be greatly appreciated,Kenny.
View 9 Replies
View Related
Aug 1, 2007
Hi All,
I can run the report if I write following in the query and run it as text in report designer's data tab it works fine.
exec abc '9B95363B-F82D-4E55-AD89-2AD928AC981F',NULL,NULL,'07/03/2006',07/08/2006'
But when I am trying to run it as stored procedure as follow
abc
and I assign the same value for the parameter in Define Query Parameter dialog box. it gives following error.
"
an error occured while executing the query.
Failed to convert parameter value from string to guid.
Additiona Information :
failed to convert parameter value from a string to a guid.(system.data)
"
Thanks for help.
View 8 Replies
View Related
Feb 10, 2008
Hi, i have some problems passing a guid parameter to a stored procedure; the code is below and the error i get is;
Failed to convert parameter value from a String to a Guid
conn = new SqlConnection(ConfigurationManager.ConnectionStrings["LocalSqlServer"].ConnectionString);
cmd = new SqlCommand("spInsKeyswap_history", conn);
cmd.CommandType = CommandType.StoredProcedure;
conn.Open();
MembershipUser mu = Membership.GetUser(User.Identity.Name);
guid gdUserID = mu.ProviderUserKey;
cmd.Parameters.Add("@user_title", SqlDbType.VarChar, 50);
cmd.Parameters.Add("@first_name", SqlDbType.VarChar, 20);
cmd.Parameters.Add("@last_name", SqlDbType.VarChar, 50);
cmd.Parameters.Add("@email", SqlDbType.VarChar, 50);
cmd.Parameters.Add("@birthday", SqlDbType.VarChar, 15);
cmd.Parameters.Add("@alternate_number", SqlDbType.VarChar, 50);
cmd.Parameters.Add("@msisdn", SqlDbType.VarChar, 50);
cmd.Parameters.Add("@call1", SqlDbType.VarChar, 50);
cmd.Parameters.Add("@call2", SqlDbType.VarChar, 50);
cmd.Parameters.Add("@call3", SqlDbType.VarChar, 50);
cmd.Parameters.Add("@new_sim_msidn", SqlDbType.VarChar, 50);
cmd.Parameters.Add("@dealer_id", SqlDbType.UniqueIdentifier);
cmd.Parameters.Add("@status_code", SqlDbType.Int);
cmd.Parameters.Add("@support_id", SqlDbType.Int);
cmd.Parameters.Add("@return_value", SqlDbType.Int);
cmd.Parameters["@user_title"].Value = txtTitle.Text.ToString();
cmd.Parameters["@first_name"].Value = txtFirstName.Text.ToString();
cmd.Parameters["@last_name"].Value = txtLastName.Text.ToString();
cmd.Parameters["@email"].Value = txtEmailAddress.Text.ToString();
cmd.Parameters["@birthday"].Value = txtBirthday.Text;
cmd.Parameters["@alternate_number"].Value = txtAlternate.Text.ToString();
cmd.Parameters["@msisdn"].Value = txtNew.Text.ToString();
cmd.Parameters["@call1"].Value = txtCall1.Text.ToString();
cmd.Parameters["@call2"].Value = txtCall2.Text.ToString();
cmd.Parameters["@call3"].Value = txtCall3.Text.ToString();
cmd.Parameters["@new_sim_msidn"].Value = txtOld.Text.ToString();
//get logged in users user_id from membership
cmd.Parameters["@dealer_id"].Value = gdUserID;
cmd.Parameters["@status_code"].Value = 1;
cmd.Parameters["@support_id"].Value = 0;
cmd.Parameters["@return_value"].Direction = ParameterDirection.ReturnValue;
cmd.ExecuteNonQuery();
int returnValue = (int)cmd.Parameters["@return_value"].Value;
View 1 Replies
View Related
Aug 21, 2007
Here's a problem description I read on another post but I have the same issue:
I am trying to Import Data from a csv file into a SQL Sever table. The Data being imported has a Unique Identifier in it but it is being considered as DT_WSTR datatype in SSIS
When i directly try to import, it gives an error:
The conversion returned status value 2 and status text "The value could not be converted because of a potential loss of data.".
I Tried to use Data Conversion to convert it to DT_GUID and import into SQL Server table but it again throws the above error.
Anyone has a clue?
Thanks!
View 3 Replies
View Related
Mar 23, 2008
System.OverflowException: Value was either too large or too small for an
Int32. Why does this error originate in the following line?"SqlCommand cmd = new SqlCommand("SELECT Count(*) FROM Contacts", conn)........ ..........DataSetContacts.ContactsRow row = ds.Contacts.NewContactsRow();..................row["ContactNumber"] = Convert.ToInt32(txtContactNo.Text);" ContactNumber field is SqlDbType.Int.
View 3 Replies
View Related
Sep 16, 2004
I have written a function as below to pass some value and get aNOTHER VALUE DURING THE RUNTIME
-----------------------------------------------
Sub ExpiaryDate(ByVal Expr1 As String, ByVal Expr2 As String)
Dim strSQLDDL As String = "SELECT STATMENT "
Dim SQlCommand As New SQlCommand(strSQLDDL, mySqlConnection)
SQlCommand.CommandType = CommandType.Text
Dim Colleague_CN As String = Int32.Parse(Expr1)
Dim Course_ID As String = Int32.Parse(Expr2)
Dim parameterEventType_ID As SqlParameter = _
New SqlParameter("@Colleague_CN", SqlDbType.NVarChar, 50)
parameterEventType_ID.Value = Colleague_CN
SQlCommand.Parameters.Add(parameterEventType_ID)
Dim parameterCourse_ID As SqlParameter = _
New SqlParameter("@Course_ID", SqlDbType.NVarChar, 50)
parameterCourse_ID.Value = Course_ID
SQlCommand.Parameters.Add(parameterCourse_ID)
Dim myDataAdapter As SqlDataAdapter = New _
SqlDataAdapter(SQlCommand)
myDataAdapter.Fill(DivisionDataSet, "ExpiaryDate")
myDataAdapter.Update(DivisionDataSet, "ExpiaryDate")
DivisionDataSet.AcceptChanges()
End Sub
Everything was fine as far as i am passing an integer.
Now i need to pass a combination of numbers and letters( NVarChar)
HOW DO I GETAROUND THIS PROBLEM
WHEN I USE THIS FUNCTION I GET ERRORS
SOMETHING LIKE..... Input string was not in a correct format.
INDICATES --Dim Colleague_CN As String = Int32.Parse(Expr1.ToString)
AS AN ERROR
CAN ANYBODY PLEASE HELP
HOW DO I PASS A NVarChar instead
THANKS
View 4 Replies
View Related
Jul 18, 2006
Using c# in the compact framework, is there a way to do a parameterized query for counting the number of records where a specified column is null. I tried all of these, but none of them work:
cmd.Add(new SqlCeParameter("@IntColumn", SqlInt32.Null));
cmd.CommandText = "select count(*) from TableName where IntColumn is not @IntColumn";
cmd.Add(new SqlCeParameter("@IntColumn", DBNull.Value));
cmd.CommandText = "select count(*) from TableName where IntColumn is not @IntColumn";
cmd.Add(new SqlCeParameter("@IntColumn", SqlInt32.Null));
cmd.CommandText = "select count(*) from TableName where not IntColumn = @IntColumn";
cmd.Add(new SqlCeParameter("@IntColumn", DBNull.Value));
cmd.CommandText = "select count(*) from TableName where not IntColumn = @IntColumn";
cmd.Parameters.Add(new SqlCeParameter("@IntColumn", SqlDbType.Int32));
cmd.Parameters["@IntColumn"].Value = SqlInt32.Null;
cmdGetNumRead.CommandText = "select count(*) from TableName where IntColumn is not @IntColumn";
cmd.Parameters.Add(new SqlCeParameter("@IntColumn", SqlDbType.Int32));
cmd.Parameters["@IntColumn"].Value = SqlInt32.Null;
cmdGetNumRead.CommandText = "select count(*) from TableName where not IntColumn = @IntColumn";
cmd.Parameters.Add(new SqlCeParameter("@IntColumn", SqlDbType.Int32));
cmd.Parameters["@IntColumn"].Value = DBNull.Value;
cmdGetNumRead.CommandText = "select count(*) from TableName where IntColumn is not @IntColumn";
cmd.Parameters.Add(new SqlCeParameter("@IntColumn", SqlDbType.Int32));
cmd.Parameters["@IntColumn"].Value = DBNull.Value;
cmdGetNumRead.CommandText = "select count(*) from TableName where not IntColumn = @IntColumn";
cmd.Parameters.Add(new SqlCeParameter("@IntColumn", SqlDbType.Variant));
cmd.Parameters["@IntColumn"].Value = SqlInt32.Null;
cmd.CommandText = "select count(*) from Meter where IntColumn is not @IntColumn";
cmd.Parameters.Add(new SqlCeParameter("@IntColumn", SqlDbType.Variant));
cmd.Parameters["@IntColumn"].Value = SqlInt32.Null;
cmd.CommandText = "select count(*) from Meter where not IntColumn = @IntColumn";
md.Parameters.Add(new SqlCeParameter("@IntColumn", SqlDbType.Variant));
cmd.Parameters["@IntColumn"].Value = DBNull.Value;
cmd.CommandText = "select count(*) from Meter where IntColumn is not @IntColumn";
cmd.Parameters.Add(new SqlCeParameter("@IntColumn", SqlDbType.Variant));
cmd.Parameters["@IntColumn"].Value = DBNull.Value;
cmd.CommandText = "select count(*) from Meter where not IntColumn = @IntColumn";
Whenever I use a "is not" in the query I get an exception, otherwise it returns a count of 0 which is not accurate. Any help will be appreciated.
View 5 Replies
View Related
Mar 4, 2008
How do I update the OrderGUID column in Table B with Values from OrderGUID column in Table A. I have already populated the OrderGUID column in Table A using NEWSEQUENTIALID(). Now I need to populate the OrderGUID column in Table B with Matching GUID values from the OrderGUID Column in Table A.
Does any one have a script to accomplish this task. thanks
View 4 Replies
View Related
Feb 1, 2001
we are currently using id's as primary key and replication is not part of our project.
will this be a problem if we decide to do replication? will microsoft generate an identifier then.
what is the advantages of using GUID now or doing it latter?
View 1 Replies
View Related
May 26, 2006
Hello,
I'm working on a smart client app that has an offline sql express store and needs to work with several types of central databases (support for multiple products - ms sql, DB2 etc)
While trying to put together some offline functionality that needs the user to create records on the offline sql express data store, we've run into the need of being able to uniquely identify records so replicating the data in the offline store back into the primary database should not be a problem.
The data created offline spans many tables and involves several tables with relation ships - FK etc...Clearly not a simple case of store and forward.
We dont want to get into the mess of performing key replacement during a synch job with the server. Thats way too much trouble.
GUID seems like a good choice, but as always we have several stake holders having different opinions. And with databases other than MS SQL we will have to store them as strings.
To cut to the chase - can we not hash a GUID to get an integer while retaining atleast the same likelyhood of producing unique ids ? [no drop]
Thanks,
Aviansh
View 13 Replies
View Related
Apr 13, 2007
I am using a SqlDatasource and need to set a SelectParamter to the ProviderUserKey (The GUID of the user when Profiles are enabled)
Can anyone tell me whether it is possible and How?
I am currently using the session state to store it in and then using the session=... to get the value into the parameter.
Is there a direct way of passing this value into a SelectParameter when using a SqlDataSource?
Thanks in advance.
View 3 Replies
View Related
Sep 25, 2007
Hi Everyone,
I'm trying to create a SQL Delete statement using a string builder and the WHERE clause uses a Guid. Here is the code:stb.Append("DELETE FROM UserRights WHERE UserIDPtr = ");
stb.Append(TargetUserID);The resulting string is: "DELETE FROM UserRights WHERE UserIDPtr = e01549fb-edf5-4668-de8b-b13dd5661a6e"
When I try to do an ExecuteNonQuery() using the string as the CommandText, I get an error.
Invalid column name 'e01549fb',Invalid column name 'edf5',Invalid column name 'de8b',Invalid column name 'b13dd5661a6e'
It is also strange that '4668' did not show up as an invalid column name, but I don't think that is relavent to this issue.
Can someone show me (or point me to an article) about using Guid's in a text string as a SQL command? Thanks in advance!
View 2 Replies
View Related
May 5, 2008
My database is using the membership store for all the user information. I added a tabel "Skills" with 3 fields "SkillID (GUID)" "SeekerID (GUID, This is the UserId)" and "SkillName ( Varchar(MAX))"
on the page i have a ListView setup to display the SkillName fields based on the SeekerID.
The original code was Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
' Get a reference to the currently logged on user Dim CurrentUser As MembershipUser = Membership.GetUser
' Determine the currently logged on user's UserId value
Dim SeekerID As Guid = CType(CurrentUser.ProviderUserKey, Object)
End Subthat kept returning string to GUID conversion errors, so i had to change Dim SeekerID As Guid = CType(CurrentUser.ProviderUserKey, Object) to Dim SeekerID As Object = CType(CurrentUser.ProviderUserKey.ToString(), Object) that appears to be working now. On the same page however, I want to insert records into the table, I tried 2 options both of which have a different problem.
Option 1: Use a textbox (ID = NewSkill) and a button with the following code on it:
Protected Sub SetNewSkill_Click(ByVal sender As Object, ByVal e As System.EventArgs) Dim CurrentUser As MembershipUser = Membership.GetUser
Dim SeekerGUID As Object = CType(CurrentUser.ProviderUserKey, Object)
Dim NewSkill As TextBox = CType(FindControl("NewSkill"), TextBox) Dim connectionString As String = ConfigurationManager.ConnectionStrings("QJSdatabase").ConnectionString()
Dim insertSql As String = "INSERT INTO Skills(SeekerID, SkillName)VALUES(@SeekerGUID, @NewSkill)" Using myConnection As New SqlConnection(connectionString)
myConnection.Open() Dim myCommand As New SqlCommand(insertSql, myConnection)
myCommand.Parameters.AddWithValue("@SeekerGUID", SeekerGUID) myCommand.Parameters.AddWithValue("@NewSkill", NewSkill.Text.Trim())
myCommand.ExecuteNonQuery()
myConnection.Close()
End Using
End Sub
Problem: myCommand.Parameters.AddWithValue("@NewSkill", NewSkill.Text.Trim()) gets outlined and returns the error: Object reference not set to an instance of an object
Option 2: Use a DetailsView linked to a SQLDataSource on the page
<asp:DetailsView ID="DetailsView1" runat="server" Height="50px" Width="210px"
AutoGenerateRows="False" DataSourceID="SqlDataSource2" DefaultMode="Insert"> <Fields>
<asp:BoundField DataField="SkillName" HeaderText="Add Skill:" SortExpression="SkillName" />
<asp:CommandField ShowInsertButton="True" />
<asp:TemplateField InsertVisible="False">
<EditItemTemplate>
<asp:TextBox ID="TextBox1" runat="server"></asp:TextBox>
</EditItemTemplate>
<ItemTemplate>
<asp:Label ID="Label1" runat="server"></asp:Label>
</ItemTemplate>
</asp:TemplateField>
</Fields>
</asp:DetailsView>
<asp:SqlDataSource ID="SqlDataSource2" runat="server" ConnectionString="<%$ ConnectionStrings:database %>"
DeleteCommand="DELETE FROM [Skills] WHERE [SkillID] = @SkillID" InsertCommand="INSERT INTO [Skills] ([SeekerID], [SkillName]) VALUES (@SeekerGUID, @SkillName)"
SelectCommand="SELECT SkillName FROM [Skills]"
UpdateCommand="UPDATE [Skills] SET [SkillName] = @SkillName WHERE [SkillID] = @SkillID">
<DeleteParameters>
<asp:Parameter Name="SkillID" Type="Object" />
</DeleteParameters>
<InsertParameters>
<asp:Parameter Name="SeekerGUID" Type="Object" />
<asp:Parameter Name="SkillName" Type="String" />
</InsertParameters>
<UpdateParameters>
<asp:Parameter Name="SkillName" Type="String" />
<asp:Parameter Name="SkillID" Type="Object" />
</UpdateParameters>
</asp:SqlDataSource>
http://junk.icore-studios.com/junk/Codeissues/postresumeerror.html
The @SeekerGUID is being generated by the same pageload code as the first chunk i gave (I have 2 variables SeekerID is the GUID converted to string to work with the ListView filter and SeekerGUID is the GUID)
Ultimatly getting either option to work would be fine. Though I think the second would be preferable because I think it'd be easier to replicate later on.
Thanks in advance for your time and any help
View 3 Replies
View Related
Apr 17, 2004
Hi,
I am having a hard time updating a database row using a UNIQUEIDENTIFIER. I retrieve the row into a datagrid and then use the GUID as a parameter to a stored procedure, but it doesn't update. If I run the query in SQL Analyser ... it works. Any ideas ? Here's my stored proc ... I tried passing a varchar and doing the conversion in the SP ... no go !! I am using MApplicationBlockD.
CREATE PROCEDURE spScanUpdate
@id varchar (100),
@name varchar (75)
AS
DECLARE @GUID_ID as uniqueidentifier
SELECT@GUID_ID = CAST ( @id as uniqueidentifier )
UPDATE tScan
SET name = @name
WHEREid = @GUID_ID
GO
View 5 Replies
View Related
Apr 17, 2006
I use MS SQL Server 2005...Is there a structural advantage/disadvantage with using GUID as oposed to an integer?(also I use the sqltableprofileprovider and it doesnt seem to work with uniqueidentifiers)
View 6 Replies
View Related
Sep 26, 2007
does SQL Server have the equivalent of the Identity or Scope_Identity functions that can be used to return the last GUID PK?
View 5 Replies
View Related
Apr 11, 2008
I have a database with tables with GUID's als primary keys.
Because of the uniqueness GUID's are a performance hit on INSERT records.
So I wanted to use NEWSQUENTIALID() to make INSERTS faster.
Does NEWSQUENTIALID() increase performance as well with SELECT statements? Or is the benefit between NEWID() and NEWSQUENTIALID() only when INSERTing records?
Henri
~~~~
There's no place like 127.0.0.1
View 3 Replies
View Related
Apr 29, 2008
I'm reluctant to admit I'm in love with uniqueidentifiers AKA guid's.
However, this love comes with a cost because of the size and thus SQL Cache and thus IO reads (and fragmented index pages and so on)
My love has to do with generic programming and keeping multiple database updateable (adding core functionality with the flexibility to let users add and change data in tables that have core data in it as well). Also merging databases is easy or relate different entities by storing a metadata link table.
So, what I'm trying to do is making the disadvantages as small as possible.
So I'm using NEWSEQUENTIAL Id's and retrieve new made records with OUTPUT as TABLE.
So I changed the default CLUSTERED INDEX as NON-CLUSTERED.
I'm not fond on usings numerics for some primary keys and uniqueidentifiers for others.
What else can I do to keep using GUID's as primary keys with as less disadvantages as possible?
Henri
~~~~
There's no place like 127.0.0.1
View 13 Replies
View Related
Mar 13, 2008
I have a table profiles and a table resumes.
The id's are currently int indentity fields.
I was thinking of using a GUID as ID.
Why would i do this ?
In my webapplication I have i.e. this page
DeleteProfile.aspx?profileId=1
I don't want to give the user the ability to change this to f.e.
DeleteProfile.aspx?profileId=3
A user will almost possibly never guess a certain GUID, right ?
Is this a good idea, or not ?
View 6 Replies
View Related
Jul 20, 2005
Hi,Is there any replace for "Select @@identity" that could return "justinserted" GUID as a primary key?Has anyone tested what's faster, working with Guid or Autonumber ?
View 24 Replies
View Related
Jul 20, 2005
Greetings All, I have read many upon many articles here regarding GUIDdata types and uniqueness. There have been many opinions regardingthe effectiveness of GUID's and when they should/should not be used.However, every article strongly implies, if it does not state itoutright, that GUID's are always unique. My question is this, whathappens if you have a database that uses GUID's and the NIC is changedout on the box? From what I understand the MAC address of the NIC isused as part of the algorithm to generate a GUID. If you change outthe NIC after generating 1 billion GUID's do you run the chance ofgenerating a duplicate GUID?I look forward to your insightfulness on this issue.Regards, Louis.
View 4 Replies
View Related
Feb 26, 2007
Hi, please can someone be so kind and tell me the fastet way to get the GUID of the running SQLExpress instance ?
Sincerely,gonzo883.
View 5 Replies
View Related
Apr 28, 2008
Exists any easy way to renew component GUID without having to recreate the component?
View 6 Replies
View Related
Mar 12, 2006
I have been trying to setup the GUID new GUID when I add a row into a Pocket PC WM 5.0 Mobile SQL (*.sdf) utilizing C# through Visual Studio 2005 - targetting Pocket PC Smart Device
Any help would be most welcome...
Thanks
View 7 Replies
View Related
Sep 17, 2006
I am reading a book and it talks a little bit about using GUIDs as primary keys. I am very confused about this because if this is a generated value per table, how could you use it as a foreign key in another table as it appears to be uniquely generated per table. Here is the code in the book which I don't understand. Can someone explain this in simple terms?
I know the identity column would be a problem if I had a multi-terabyte database with huge tables, so what do I do in this situation?
create table dbo.product(
productid uniqueidentifier not null
rowguidcol default (newid())
primary key nonclustered
etc
thx,
Kat
View 5 Replies
View Related
Oct 24, 2007
once upon a time someone told me how to do this, but i forget, and it was for classic asp..
so what im trying to do is create a new record (a workstation) and get back the auto generated ID (its not actually a GUID, its an int which is set to the identity) and then once i have that create other records (for external devices, different table) that will have a link to which machine they are attached to (that Id im looking to get returned)
I know this can be done in a two step process, create the record, query it for its id, and then slap that in my next insert statement for the external devices... but... i know there was a way to do it before and i assume there is a way to do it now...
anyone know how?
Thanks
Justin
View 8 Replies
View Related
Jun 12, 2008
I need to execute stored procedure which is suppose to return GUID to my IF statement and if it is Nothing I execute other Stored procedures else some other procedures. My problem is that even though by looking at the data I know that after the execution of the procedure it should return some guid value it doesn't anybody who had the same issue??? That is the code block where I am trying to return guid from my stored procedure: getGroupID.Parameters("@GroupName").Value = dr.Item("Group ID").ToString() If getGroupID.ExecuteScalar() = Nothing Then 'Find Group by IP address if input Data Table doesn't have group getGroupIDByIP.Parameters("@IP").Value = dr.Item("IP").ToString() If getGroupIDByIP.ExecuteScalar() = Nothing Then insertGroup.Parameters("@GroupID").Value = Guid.NewGuid insertGroup.Parameters("@Group").Value = dr.Item("Group ID") insertGroup.Parameters("@ACCID").Value = getAccID.ExecuteScalar() insertGroup.ExecuteNonQuery() command.Parameters("@Group_ID").Value = getGroupID.ExecuteScalar() Else command.Parameters("@Group_ID").Value = getGroupIDByIP.ExecuteScalar() End If Else command.Parameters("@Group_ID").Value = getGroupID.ExecuteScalar() End If Thank you
View 2 Replies
View Related
May 13, 2004
Dear SQL,
I need to SELECT something from a database that has a UNIQUEIDENTIFIER (GUID) field,
If the number is wrong (has some other than A-Z 0-9) than the ASP page just freaks out and gets "error converting from a character string to uniqueidentifier"
How can I check that the GUID is OK before I SELECT ?
this is the number format:
{7A9B5F81-4936-4A31-B4E2-9168AAB75A0}
I tried to cast this "error" number with no successs:
"WHERE Deceased_ID = cast('"& "---------4936-4A31-B4E2-9168AAB75A0" &"' as uniqueidentifier)"
Thanks in advance, Yovav.
View 5 Replies
View Related
May 23, 2004
I am having a terrible time doing an insert.... dispite what the error message says, I think it has something to do with trying to insert a GUID (my primary key).... but I am probably wrong :-)
Any ideas
The error message
Server Error in '/LightQuote' Application.
--------------------------------------------------------------------------------
Prepared statement '(@User_ID uniqueidentifier,@User_Type int,@Status int,@UserName ' expects parameter @UserName, which was not supplied.
Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code.
Exception Details: System.Data.SqlClient.SqlException: Prepared statement '(@User_ID uniqueidentifier,@User_Type int,@Status int,@UserName ' expects parameter @UserName, which was not supplied.
Source Error:
Line 195: dbConnection.Open()
Line 196: Try
Line 197: rowsAffected = dbCommand.ExecuteNonQuery
Line 198: Finally
Line 199: dbConnection.Close()
The Insert Function
Public Function InsertOneUser( _
ByVal user_ID As System.Guid, _
ByVal user_Type As Integer, _
ByVal status As Integer, _
ByVal userName As String, _
ByVal password As String, _
ByVal secret_Question As Integer, _
ByVal secret_Answer As String, _
ByVal company As String, _
ByVal company_Type As Integer, _
ByVal first_Name As String, _
ByVal last_Name As String, _
ByVal address1 As String, _
ByVal address2 As String, _
ByVal city As String, _
ByVal state As String, _
ByVal zip As String, _
ByVal country As String, _
ByVal day_Phone As String, _
ByVal night_Phone As String, _
ByVal fax As String, _
ByVal email As String, _
ByVal web_Site As String) As Integer
Dim myConnection As New Connection
Dim connectionString As String = myConnection.ConnString
Dim dbConnection As System.Data.IDbConnection = New System.Data.SqlClient.SqlConnection(connectionString)
Dim queryString As String = "INSERT INTO [tblUser] ([User_ID], [User_Type], [Status], [UserName], [Password], " & _
"[Secret_Question], [Secret_Answer], [Company], [Company_Type], [First_Name], [L" & _
"ast_Name], [Address1], [Address2], [City], [State], [Zip], [Country], [Day_Phone" & _
"], [Night_Phone], [Fax], [Email], [Web_Site]) VALUES (@User_ID, @User_Type, @Sta" & _
"tus, @UserName, @Password, @Secret_Question, @Secret_Answer, @Company, @Company" & _
"_Type, @First_Name, @Last_Name, @Address1, @Address2, @City, @State, @Zip, @Coun" & _
"try, @Day_Phone, @Night_Phone, @Fax, @Email, @Web_Site)"
Dim dbCommand As System.Data.IDbCommand = New System.Data.SqlClient.SqlCommand
dbCommand.CommandText = queryString
dbCommand.Connection = dbConnection
Dim dbParam_user_ID As System.Data.IDataParameter = New System.Data.SqlClient.SqlParameter
dbParam_user_ID.ParameterName = "@User_ID"
dbParam_user_ID.Value = user_ID
dbParam_user_ID.DbType = System.Data.DbType.Guid
dbCommand.Parameters.Add(dbParam_user_ID)
Dim dbParam_user_Type As System.Data.IDataParameter = New System.Data.SqlClient.SqlParameter
dbParam_user_Type.ParameterName = "@User_Type"
dbParam_user_Type.Value = user_Type
dbParam_user_Type.DbType = System.Data.DbType.Int32
dbCommand.Parameters.Add(dbParam_user_Type)
Dim dbParam_status As System.Data.IDataParameter = New System.Data.SqlClient.SqlParameter
dbParam_status.ParameterName = "@Status"
dbParam_status.Value = status
dbParam_status.DbType = System.Data.DbType.Int32
dbCommand.Parameters.Add(dbParam_status)
Dim dbParam_userName As System.Data.IDataParameter = New System.Data.SqlClient.SqlParameter
dbParam_userName.ParameterName = "@UserName"
dbParam_userName.Value = userName
dbParam_userName.DbType = System.Data.DbType.StringFixedLength
dbCommand.Parameters.Add(dbParam_userName)
Dim dbParam_password As System.Data.IDataParameter = New System.Data.SqlClient.SqlParameter
dbParam_password.ParameterName = "@Password"
dbParam_password.Value = password
dbParam_password.DbType = System.Data.DbType.StringFixedLength
dbCommand.Parameters.Add(dbParam_password)
Dim dbParam_secret_Question As System.Data.IDataParameter = New System.Data.SqlClient.SqlParameter
dbParam_secret_Question.ParameterName = "@Secret_Question"
dbParam_secret_Question.Value = secret_Question
dbParam_secret_Question.DbType = System.Data.DbType.Int32
dbCommand.Parameters.Add(dbParam_secret_Question)
Dim dbParam_secret_Answer As System.Data.IDataParameter = New System.Data.SqlClient.SqlParameter
dbParam_secret_Answer.ParameterName = "@Secret_Answer"
dbParam_secret_Answer.Value = secret_Answer
dbParam_secret_Answer.DbType = System.Data.DbType.StringFixedLength
dbCommand.Parameters.Add(dbParam_secret_Answer)
Dim dbParam_company As System.Data.IDataParameter = New System.Data.SqlClient.SqlParameter
dbParam_company.ParameterName = "@Company"
dbParam_company.Value = company
dbParam_company.DbType = System.Data.DbType.StringFixedLength
dbCommand.Parameters.Add(dbParam_company)
Dim dbParam_company_Type As System.Data.IDataParameter = New System.Data.SqlClient.SqlParameter
dbParam_company_Type.ParameterName = "@Company_Type"
dbParam_company_Type.Value = company_Type
dbParam_company_Type.DbType = System.Data.DbType.Int32
dbCommand.Parameters.Add(dbParam_company_Type)
Dim dbParam_first_Name As System.Data.IDataParameter = New System.Data.SqlClient.SqlParameter
dbParam_first_Name.ParameterName = "@First_Name"
dbParam_first_Name.Value = first_Name
dbParam_first_Name.DbType = System.Data.DbType.StringFixedLength
dbCommand.Parameters.Add(dbParam_first_Name)
Dim dbParam_last_Name As System.Data.IDataParameter = New System.Data.SqlClient.SqlParameter
dbParam_last_Name.ParameterName = "@Last_Name"
dbParam_last_Name.Value = last_Name
dbParam_last_Name.DbType = System.Data.DbType.StringFixedLength
dbCommand.Parameters.Add(dbParam_last_Name)
Dim dbParam_address1 As System.Data.IDataParameter = New System.Data.SqlClient.SqlParameter
dbParam_address1.ParameterName = "@Address1"
dbParam_address1.Value = address1
dbParam_address1.DbType = System.Data.DbType.StringFixedLength
dbCommand.Parameters.Add(dbParam_address1)
Dim dbParam_address2 As System.Data.IDataParameter = New System.Data.SqlClient.SqlParameter
dbParam_address2.ParameterName = "@Address2"
dbParam_address2.Value = address2
dbParam_address2.DbType = System.Data.DbType.StringFixedLength
dbCommand.Parameters.Add(dbParam_address2)
Dim dbParam_city As System.Data.IDataParameter = New System.Data.SqlClient.SqlParameter
dbParam_city.ParameterName = "@City"
dbParam_city.Value = city
dbParam_city.DbType = System.Data.DbType.StringFixedLength
dbCommand.Parameters.Add(dbParam_city)
Dim dbParam_state As System.Data.IDataParameter = New System.Data.SqlClient.SqlParameter
dbParam_state.ParameterName = "@State"
dbParam_state.Value = state
dbParam_state.DbType = System.Data.DbType.StringFixedLength
dbCommand.Parameters.Add(dbParam_state)
Dim dbParam_zip As System.Data.IDataParameter = New System.Data.SqlClient.SqlParameter
dbParam_zip.ParameterName = "@Zip"
dbParam_zip.Value = zip
dbParam_zip.DbType = System.Data.DbType.StringFixedLength
dbCommand.Parameters.Add(dbParam_zip)
Dim dbParam_country As System.Data.IDataParameter = New System.Data.SqlClient.SqlParameter
dbParam_country.ParameterName = "@Country"
dbParam_country.Value = country
dbParam_country.DbType = System.Data.DbType.StringFixedLength
dbCommand.Parameters.Add(dbParam_country)
Dim dbParam_day_Phone As System.Data.IDataParameter = New System.Data.SqlClient.SqlParameter
dbParam_day_Phone.ParameterName = "@Day_Phone"
dbParam_day_Phone.Value = day_Phone
dbParam_day_Phone.DbType = System.Data.DbType.StringFixedLength
dbCommand.Parameters.Add(dbParam_day_Phone)
Dim dbParam_night_Phone As System.Data.IDataParameter = New System.Data.SqlClient.SqlParameter
dbParam_night_Phone.ParameterName = "@Night_Phone"
dbParam_night_Phone.Value = night_Phone
dbParam_night_Phone.DbType = System.Data.DbType.StringFixedLength
dbCommand.Parameters.Add(dbParam_night_Phone)
Dim dbParam_fax As System.Data.IDataParameter = New System.Data.SqlClient.SqlParameter
dbParam_fax.ParameterName = "@Fax"
dbParam_fax.Value = fax
dbParam_fax.DbType = System.Data.DbType.StringFixedLength
dbCommand.Parameters.Add(dbParam_fax)
Dim dbParam_email As System.Data.IDataParameter = New System.Data.SqlClient.SqlParameter
dbParam_email.ParameterName = "@Email"
dbParam_email.Value = email
dbParam_email.DbType = System.Data.DbType.StringFixedLength
dbCommand.Parameters.Add(dbParam_email)
Dim dbParam_web_Site As System.Data.IDataParameter = New System.Data.SqlClient.SqlParameter
dbParam_web_Site.ParameterName = "@Web_Site"
dbParam_web_Site.Value = web_Site
dbParam_web_Site.DbType = System.Data.DbType.StringFixedLength
dbCommand.Parameters.Add(dbParam_web_Site)
Dim rowsAffected As Integer = 0
dbConnection.Open()
Try
rowsAffected = dbCommand.ExecuteNonQuery
Finally
dbConnection.Close()
End Try
Return rowsAffected
End Function
The Sub that calls the Insert function
Public Sub Add_New_User()
m_User_ID = New Guid 'm_User_ID is the private field for the public User_ID Property
myData.InsertOneUser( _
User_ID, _
User_Type, _
Status, _
UserName, _
Password, _
Secret_Question, _
Secret_Answer, _
Company, _
Company_Type, _
First_Name, _
Last_Name, _
Address1, _
Address2, _
City, _
State, _
Zip, _
Country, _
Day_Phone, _
Night_Phone, _
Fax, _
Email, _
Web_Site)
End Sub
View 2 Replies
View Related