Problem Using GUID as SQLDataSource Parameter

W

Wayne Wengert

Using VSNET2005. I want to insert some rows into a table. Each row has 2
columns, "memberid" which is a GUID and "Interests" which is a varchar. I
created a SQLDataSource with the values to insert as parameters as shown
here
=====================================================
<asp:SqlDataSource ID="SqlDataSource2" runat="server" ConnectionString="<%$
ConnectionStrings:GoodSamSiteDB %>"

DeleteCommand="DELETE FROM [gs_MemberInterests] WHERE [memberid] = @memberid
AND [Interest] = @Interest"

InsertCommand="INSERT INTO [gs_MemberInterests] ([memberid], [Interest])
VALUES (@memberid, @Interest)"

SelectCommand="SELECT * FROM [gs_MemberInterests] WHERE ([memberid] =
@memberid)">

<DeleteParameters>

<asp:parameter Name="memberid" Type="Object" />

<asp:parameter Name="Interest" Type="String" />

</DeleteParameters>

<SelectParameters>

<asp:SessionParameter Name="memberid" SessionField="currmember"
Type="Object" />

<asp:SessionParameter Name="Interest" SessionField="currinterest"
Type="String" />

</SelectParameters>

<InsertParameters>

<asp:parameter Name="memberid" Type="Object" />

<asp:parameter Name="Interest" Type="String" />

</InsertParameters>

</asp:SqlDataSource>

=========================================

When I try to do the insert I get the following error:

================ Error ===================

Disallowed implicit conversion from data type sql_variant to data type
uniqueidentifier, table 'DB_136571.dbo.gs_MemberInterests', column
'memberid'. Use the CONVERT function to run this query.

==========================================

The code to set and use the memerid parameter is shown here

==================================================

Dim guidMemberid As Guid = CType(user.ProviderUserKey, Guid)

Session("currmember") = guidMemberid

Dim item As DataListItem

For Each item In DataList1.Items

If Not (CType(item.FindControl("CheckBox1"), CheckBox) Is Nothing) And
CType(item.FindControl("CheckBox1"), CheckBox).Checked Then



Session("currinterest") = CType(item.FindControl("CheckBox1"),
CheckBox).Text

SqlDataSource2.Insert()

End If

Next item

======================================

What is the right way to do this?
 
W

Wayne Wengert

Thanks JR. That seems to have cleared that problem. What do I do that caused
that to get added to the code?

Also, if I may, will the insert process automatically use the session values
for the parameters as specified in the select statement? I am not clear on
what makes the insert statement use my session values.

Wayne
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,769
Messages
2,569,580
Members
45,054
Latest member
TrimKetoBoost

Latest Threads

Top