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 uniqueidentifier."
I'd sure appreciate any help in resolving the issue. The code is below. Thank you.
---------------
The table definition is as follows:
GoalEventID : uniqueidentifier : pk : default=newid() : RowGuid=Yes
GoalID : uniqueidentifier : fk
GoalValue : float
GoalDateTime : datetime - <asp:SqlDataSource ID="SqlDataSource1" runat="server"
-
ConflictDetection="CompareAllValues"
-
ConnectionString="<%$ ConnectionStrings:goals_goalsConnectionString1 %>"
-
DeleteCommand="DELETE FROM [tblGoalEvents] WHERE [GoalEventID] = @original_GoalEventID AND [GoalID] = @original_GoalID AND [GoalValue] = @original_GoalValue AND [GoalDateTime] = @original_GoalDateTime"
-
InsertCommand="INSERT INTO tblGoalEvents(GoalEventID, GoalID, GoalValue, GoalDateTime) VALUES (@GoalEventID, @GoalID, @GoalValue, @GoalDateTime)"
-
OldValuesParameterFormatString="original_{0}"
-
SelectCommand="SELECT tblGoals.GoalID FROM tblGoals INNER JOIN vwUsers ON tblGoals.UserID = vwUsers.UserID WHERE (tblGoals.GoalName = @GoalName) AND (vwUsers.Email = @Email)"
-
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">
-
-
<!-- **Select, Update, and Delete commands ommitted for brevity**-->
-
-
<InsertParameters>
-
<asp:Parameter Name="GoalEventID" Type="Empty" DefaultValue="newid()" />
-
<asp:Parameter Name="GoalID" Type="Empty" />
-
<asp:Parameter Name="GoalValue" Type="Double" />
-
<asp:Parameter Name="GoalDateTime" Type="DateTime" />
-
</InsertParameters>
-
</asp:SqlDataSource>
In the page load event I have: - //...
-
goalID = new Guid(reader[0].ToString());
-
//...
-
SqlDataSource1.InsertParameters["GoalID"].DefaultValue = goalID.ToString();
-
SqlDataSource1.InsertParameters["GoalValue"].DefaultValue = goalEventValue.ToString();
-
SqlDataSource1.InsertParameters["GoalDateTime"].DefaultValue = goalDateTime.ToString();
-
SqlDataSource1.Insert();
3 20605
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 uniqueidentifier."
I'd sure appreciate any help in resolving the issue. The code is below. Thank you.
---------------
The table definition is as follows:
GoalEventID : uniqueidentifier : pk : default=newid() : RowGuid=Yes
GoalID : uniqueidentifier : fk
GoalValue : float
GoalDateTime : datetime - <asp:SqlDataSource ID="SqlDataSource1" runat="server"
-
ConflictDetection="CompareAllValues"
-
ConnectionString="<%$ ConnectionStrings:goals_goalsConnectionString1 %>"
-
DeleteCommand="DELETE FROM [tblGoalEvents] WHERE [GoalEventID] = @original_GoalEventID AND [GoalID] = @original_GoalID AND [GoalValue] = @original_GoalValue AND [GoalDateTime] = @original_GoalDateTime"
-
InsertCommand="INSERT INTO tblGoalEvents(GoalEventID, GoalID, GoalValue, GoalDateTime) VALUES (@GoalEventID, @GoalID, @GoalValue, @GoalDateTime)"
-
OldValuesParameterFormatString="original_{0}"
-
SelectCommand="SELECT tblGoals.GoalID FROM tblGoals INNER JOIN vwUsers ON tblGoals.UserID = vwUsers.UserID WHERE (tblGoals.GoalName = @GoalName) AND (vwUsers.Email = @Email)"
-
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">
-
-
<!-- **Select, Update, and Delete commands ommitted for brevity**-->
-
-
<InsertParameters>
-
<asp:Parameter Name="GoalEventID" Type="Empty" DefaultValue="newid()" />
-
<asp:Parameter Name="GoalID" Type="Empty" />
-
<asp:Parameter Name="GoalValue" Type="Double" />
-
<asp:Parameter Name="GoalDateTime" Type="DateTime" />
-
</InsertParameters>
-
</asp:SqlDataSource>
In the page load event I have: - //...
-
goalID = new Guid(reader[0].ToString());
-
//...
-
SqlDataSource1.InsertParameters["GoalID"].DefaultValue = goalID.ToString();
-
SqlDataSource1.InsertParameters["GoalValue"].DefaultValue = goalEventValue.ToString();
-
SqlDataSource1.InsertParameters["GoalDateTime"].DefaultValue = goalDateTime.ToString();
-
SqlDataSource1.Insert();
Are you sure that the GoalID and GoalEventID are Strings in your DataBase?
Make sure that your data types match....
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 uniqueidentifiers. However, I thought I'd read somewhere that it would perform implicit conversion. Regardless, knowing the database fields are uniqueidentifiers 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. - InsertCommand="INSERT INTO tblGoalEvents(GoalEventID, GoalID, GoalValue, GoalDateTime) VALUES (CAST(@GoalEventID AS UNIQUEIDENTIFIER), CAST(@GoalID AS UNIQUEIDENTIFIER), @GoalValue, @GoalDateTime)"
Suggestions? Thanks.
Sign in to post your reply or Sign up for a free account.
Similar topics
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...
|
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...
|
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
|
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...
|
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...
|
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****
...
|
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...
|
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?
|
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...
|
by: Charles Arthur |
last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
|
by: ryjfgjl |
last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
|
by: ryjfgjl |
last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
|
by: BarryA |
last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
|
by: nemocccc |
last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
|
by: Hystou |
last post by:
There are some requirements for setting up RAID:
1. The motherboard and BIOS support RAID configuration.
2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
|
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,...
|
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...
|
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...
| |