473,769 Members | 6,107 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

ASP.Net-C#: "Conversion failed... character string to uniqueidentifie r"

3 New Member
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 SqlDataSource1. Insert() I get the exception : "Conversion failed when converting from a character string to uniqueidentifie r."

I'd sure appreciate any help in resolving the issue. The code is below. Thank you.

---------------

The table definition is as follows:
GoalEventID : uniqueidentifie r : pk : default=newid() : RowGuid=Yes
GoalID : uniqueidentifie r : fk
GoalValue : float
GoalDateTime : datetime


Expand|Select|Wrap|Line Numbers
  1.     <asp:SqlDataSource ID="SqlDataSource1" runat="server" 
  2.         ConflictDetection="CompareAllValues" 
  3.         ConnectionString="<%$ ConnectionStrings:goals_goalsConnectionString1 %>" 
  4.         DeleteCommand="DELETE FROM [tblGoalEvents] WHERE [GoalEventID] = @original_GoalEventID AND [GoalID] = @original_GoalID AND [GoalValue] = @original_GoalValue AND [GoalDateTime] = @original_GoalDateTime" 
  5.         InsertCommand="INSERT INTO tblGoalEvents(GoalEventID, GoalID, GoalValue, GoalDateTime) VALUES (@GoalEventID, @GoalID, @GoalValue, @GoalDateTime)" 
  6.         OldValuesParameterFormatString="original_{0}" 
  7.         SelectCommand="SELECT tblGoals.GoalID FROM tblGoals INNER JOIN vwUsers ON tblGoals.UserID = vwUsers.UserID WHERE (tblGoals.GoalName = @GoalName) AND (vwUsers.Email = @Email)" 
  8.         UpdateCommand="UPDATE [tblGoalEvents] SET [GoalID] = @GoalID, [GoalValue] = @GoalValue, [GoalDateTime] = @GoalDateTime WHERE [GoalEventID] = @original_GoalEventID AND [GoalID] = @original_GoalID AND [GoalValue] = @original_GoalValue AND [GoalDateTime] = @original_GoalDateTime">
  9.  
  10.       <!-- **Select, Update, and Delete commands ommitted for brevity**-->
  11.  
  12.         <InsertParameters>
  13.             <asp:Parameter Name="GoalEventID" Type="Empty" DefaultValue="newid()" />
  14.             <asp:Parameter Name="GoalID" Type="Empty" />
  15.             <asp:Parameter Name="GoalValue" Type="Double" />
  16.             <asp:Parameter Name="GoalDateTime" Type="DateTime" />
  17.         </InsertParameters>
  18.     </asp:SqlDataSource>

In the page load event I have:
Expand|Select|Wrap|Line Numbers
  1.   //...
  2.   goalID = new Guid(reader[0].ToString());
  3.   //...
  4.   SqlDataSource1.InsertParameters["GoalID"].DefaultValue = goalID.ToString();
  5.   SqlDataSource1.InsertParameters["GoalValue"].DefaultValue = goalEventValue.ToString();
  6.   SqlDataSource1.InsertParameters["GoalDateTime"].DefaultValue = goalDateTime.ToString();
  7.   SqlDataSource1.Insert();
Jan 3 '08 #1
3 20648
Frinavale
9,735 Recognized Expert Moderator Expert
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 SqlDataSource1. Insert() I get the exception : "Conversion failed when converting from a character string to uniqueidentifie r."

I'd sure appreciate any help in resolving the issue. The code is below. Thank you.

---------------

The table definition is as follows:
GoalEventID : uniqueidentifie r : pk : default=newid() : RowGuid=Yes
GoalID : uniqueidentifie r : fk
GoalValue : float
GoalDateTime : datetime


Expand|Select|Wrap|Line Numbers
  1.     <asp:SqlDataSource ID="SqlDataSource1" runat="server" 
  2.         ConflictDetection="CompareAllValues" 
  3.         ConnectionString="<%$ ConnectionStrings:goals_goalsConnectionString1 %>" 
  4.         DeleteCommand="DELETE FROM [tblGoalEvents] WHERE [GoalEventID] = @original_GoalEventID AND [GoalID] = @original_GoalID AND [GoalValue] = @original_GoalValue AND [GoalDateTime] = @original_GoalDateTime" 
  5.         InsertCommand="INSERT INTO tblGoalEvents(GoalEventID, GoalID, GoalValue, GoalDateTime) VALUES (@GoalEventID, @GoalID, @GoalValue, @GoalDateTime)" 
  6.         OldValuesParameterFormatString="original_{0}" 
  7.         SelectCommand="SELECT tblGoals.GoalID FROM tblGoals INNER JOIN vwUsers ON tblGoals.UserID = vwUsers.UserID WHERE (tblGoals.GoalName = @GoalName) AND (vwUsers.Email = @Email)" 
  8.         UpdateCommand="UPDATE [tblGoalEvents] SET [GoalID] = @GoalID, [GoalValue] = @GoalValue, [GoalDateTime] = @GoalDateTime WHERE [GoalEventID] = @original_GoalEventID AND [GoalID] = @original_GoalID AND [GoalValue] = @original_GoalValue AND [GoalDateTime] = @original_GoalDateTime">
  9.  
  10.       <!-- **Select, Update, and Delete commands ommitted for brevity**-->
  11.  
  12.         <InsertParameters>
  13.             <asp:Parameter Name="GoalEventID" Type="Empty" DefaultValue="newid()" />
  14.             <asp:Parameter Name="GoalID" Type="Empty" />
  15.             <asp:Parameter Name="GoalValue" Type="Double" />
  16.             <asp:Parameter Name="GoalDateTime" Type="DateTime" />
  17.         </InsertParameters>
  18.     </asp:SqlDataSource>

In the page load event I have:
Expand|Select|Wrap|Line Numbers
  1.   //...
  2.   goalID = new Guid(reader[0].ToString());
  3.   //...
  4.   SqlDataSource1.InsertParameters["GoalID"].DefaultValue = goalID.ToString();
  5.   SqlDataSource1.InsertParameters["GoalValue"].DefaultValue = goalEventValue.ToString();
  6.   SqlDataSource1.InsertParameters["GoalDateTime"].DefaultValue = goalDateTime.ToString();
  7.   SqlDataSource1.Insert();
Are you sure that the GoalID and GoalEventID are Strings in your DataBase?
Make sure that your data types match....
Jan 4 '08 #2
blazeboy
3 New Member
Are you sure that the GoalID and GoalEventID are Strings in your DataBase?
Make sure that your data types match....
I know that they are NOT strings in the database. They are uniqueidentifie rs. However, I thought I'd read somewhere that it would perform implicit conversion. Regardless, knowing the database fields are uniqueidentifie rs and not strings, how would I pass the parameters as GUIDs? There is no 'Type="Empty"'

I have also tried casting them in the SQL statement (as follows), but I get the same "conversion " error message.

Expand|Select|Wrap|Line Numbers
  1. InsertCommand="INSERT INTO tblGoalEvents(GoalEventID, GoalID, GoalValue, GoalDateTime) VALUES (CAST(@GoalEventID AS UNIQUEIDENTIFIER), CAST(@GoalID AS UNIQUEIDENTIFIER), @GoalValue, @GoalDateTime)" 
Suggestions? Thanks.
Jan 4 '08 #3
blazeboy
3 New Member
I've found the solution. This post had the answer: http://www.devnewsgroups.net/group/m...opic10857.aspx


i figuried it out. you have to do ..

"'{" & (new guid(str)).toSt ring("D") & "}'"
That worked for me!
Jan 7 '08 #4

Sign in to post your reply or Sign up for a free account.

Similar topics

1
36083
by: Ren? M?hle | last post by:
I have a psp script with a procedure just to run an update on one table. The Problem occurs when I try to compile this script with pspload: ORA-20006: "frsys_updatereport.psp": compilation failed with the following errors. ORA-06502: PL/SQL: numeric or value error: character string buffer too small Here the whole script:
1
3473
by: rusttree | last post by:
I'm working on a program that manipulates bmp files. I know the offset location of each piece of relevent data within the bmp file. For example, I know the 18th through 21st byte is an integer value representing the width of the bmp image. So far, I have been able to use fstream's seek, write, and read to pull out chucks of bytes and convert them to usable integers straight out of the binary file. It works well, but over the course of...
2
13214
by: jt | last post by:
Looking for an example how to convert and CString to an ASCII character string. Any examples on how to do this? Thank you, jt
0
2179
by: MLH | last post by:
Is an apostrophe a character of special significance to MySQL in a way that would cause "Bob's dog" to become translated into a 12-character string when typed into a MySQL memo field? If I type Bob's dog into an Access memo field, I get a string that is 9-characters long. When I read "Bob's dog" from a memo field in a MySQL table attacted to MS Access via MyODBC driver, it displays as "Bob's dog" - a twelve character string. the '...
7
2514
by: Justin | last post by:
i need to build the unsigned character string: "PR0N\0Spam\0G1RLS\0Other\0Items\0\0\0" from the signed character string: "PR0N Spam G1RLS Other Items" Tokeninzing the character string is not a problem. I can't solve my concatenation problem. I've researched this topic extensively and I've found nothing to help. Failure resulted when I used memcpy,_mbscat, and various other methods. If anyone knows how to build a unsigned
5
4853
by: Karthik | last post by:
Hello! I am not a wizard in this area! Just need some help out in this. I am trying to convert bstr string to new character string. Here is the snippet of my code. **** Code Start**** GlobalInterfacePtr->GetName(bstr, bstrTNamePtr, &retVal);
25
6547
by: lovecreatesbeauty | last post by:
Hello experts, I write a function named palindrome to determine if a character string is palindromic, and test it with some example strings. Is it suitable to add it to a company/project library as a small tool function according to its quality? I will be very happy to get your suggestion from every aspect on it: interface design, C language knowledge or algorithm efficient. Sincerely,
8
11881
by: Brand Bogard | last post by:
Does the C standard include a library function to convert an 8 bit character string to a 16 bit character string?
2
11185
by: bipinskulkarni | last post by:
Hi, i have a field createdby with datatype GUID. In following query ,i encountered with the error "Conversion failed when converting from a character string to uniqueidentifier" select ISNULL(VW_tbl_ChildProducts.createdBy,' ' ) as createdBy from table.
0
9589
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
10211
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
9994
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
9863
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 protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
1
7408
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
6673
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
5298
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
5447
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
3958
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

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.