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>
<asparameter Name="memberid" Type="Object" />
<asparameter Name="Interest" Type="String" />
</DeleteParameters>
<SelectParameters>
<asp:SessionParameter Name="memberid" SessionField="currmember"
Type="Object" />
<asp:SessionParameter Name="Interest" SessionField="currinterest"
Type="String" />
</SelectParameters>
<InsertParameters>
<asparameter Name="memberid" Type="Object" />
<asparameter 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?
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>
<asparameter Name="memberid" Type="Object" />
<asparameter Name="Interest" Type="String" />
</DeleteParameters>
<SelectParameters>
<asp:SessionParameter Name="memberid" SessionField="currmember"
Type="Object" />
<asp:SessionParameter Name="Interest" SessionField="currinterest"
Type="String" />
</SelectParameters>
<InsertParameters>
<asparameter Name="memberid" Type="Object" />
<asparameter 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?