English 中文(简体)
不允许从数据类型“ql_variant”向独一无二的识别器进行合法转换。 利用CONVERT职能管理这一查询
原标题:Implicit conversion from data type sql_variant to uniqueidentifier is not allowed. Use the CONVERT function to run this query

我正在建立一个网站,现在使用微软视像网络开发商2010年快车,我使用了<代码>“createUserWizard”的工具箱。 然后,我将<代码>用户Id列入我的<代码>“客户信息”的表格列入<代码>“数据类型=uniqueidentifier”,因为我需要将其与表格中的用户名称联系起来。

稍后,我需要将我的<代码>>Order”表与“CustomerInfo的表格链接,这样,我就把我的<编码>加密Id数据类型=uniqueidentifier。 然后,我计划将我的命令细节插入Order”的表格,但我的问题是:

"Implicit conversion from data type sql_variant to uniqueidentifier is not allowed. Use the CONVERT function to run this query".

I search and find some answer like datatype of the parameter set to "Empty"or delete it. but then I have this error

" Conversion failed when converting from character string to uniqueidentifier."

这是我所领导的。

<asp:SqlDataSource ID="SqlDataSource1" runat="server" ConnectionString="<%$ ConnectionStrings:ConnectionString %>" 
                                    DeleteCommand="DELETE FROM [Order] WHERE [orderId] = @orderId" 
                                    InsertCommand="INSERT INTO [Order] ([orderId], [userId], [Services], [PickUpDate], [PickUpTime], [SpecialDate], [SpecialTime]) VALUES (@orderId, @userId, @Services, @PickUpDate, @PickUpTime, @SpecialDate, @SpecialTime)" 
                                    SelectCommand="SELECT * FROM [Order]" 

                                    UpdateCommand="UPDATE [Order] SET [userId] = @userId, [Services] = @Services, [PickUpDate] = @PickUpDate, [PickUpTime] = @PickUpTime, [SpecialDate] = @SpecialDate, [SpecialTime] = @SpecialTime WHERE [orderId] = @orderId">
                                    <DeleteParameters>
                                        <asp:Parameter Name="orderId" Type="Object" />
                                    </DeleteParameters>
                                    <InsertParameters>
                                    <asp:Parameter Name="orderId" Type="Object" />
                                    <asp:Parameter Name="userId" Type="Object" />
                                        <asp:Parameter Name="Services" Type="String" />
                                        <asp:Parameter Name="PickUpDate" Type="String" />
                                        <asp:Parameter Name="PickUpTime" Type="String" />
                                        <asp:Parameter Name="SpecialDate" Type="String" />
                                        <asp:Parameter Name="SpecialTime" Type="String" />
                                    </InsertParameters>
                                    <UpdateParameters>
                                        <asp:Parameter Name="userId" Type="Object" />
                                        <asp:Parameter Name="Services" Type="String" />
                                        <asp:Parameter Name="PickUpDate" Type="String" />
                                        <asp:Parameter Name="PickUpTime" Type="String" />
                                        <asp:Parameter Name="SpecialDate" Type="String" />
                                        <asp:Parameter Name="SpecialTime" Type="String" />
                                        <asp:Parameter Name="orderId" Type="Object" />
                                    </UpdateParameters>
                                </asp:SqlDataSource>

Now that I think of it, maybe there is a problem with my code in vb. I will put it here, please tell me how to do the correct way of inserting data to the database.

Protected Sub OrderButton_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles OrderButton.Click
    SqlDataSource1.InsertParameters(0).DefaultValue = Now
    SqlDataSource1.Insert()
    Response.Redirect("~/Customer/AfterOrder.aspx")
End Sub
问题回答

If you want to insert GUID from your code, you should make parameter type GUID

<asp:Parameter Name="ParamName" DbType="Guid" />

你们应当把国际统一私法作为(c#)的价值观:

SqlDataSource1.InsertParameters["ParamName"].DefaultValue = System.Guid.NewGuid().ToString();

如果你想通过显示价值,你必须使用<代码>。 CONVERT(UNI RequestIDENTIFIER, YOUR VALUE ) in the内加:

InsertCommand="INSERT INTO [Order] ([UserId], [etc]) 
VALUES (CONVERT(UNIQUEIDENTIFIER,@UserId), @etc)" 




相关问题
Anyone feel like passing it forward?

I m the only developer in my company, and am getting along well as an autodidact, but I know I m missing out on the education one gets from working with and having code reviewed by more senior devs. ...

How to Add script codes before the </body> tag ASP.NET

Heres the problem, In Masterpage, the google analytics code were pasted before the end of body tag. In ASPX page, I need to generate a script (google addItem tracker) using codebehind ClientScript ...

Transaction handling with TransactionScope

I am implementing Transaction using TransactionScope with the help this MSDN article http://msdn.microsoft.com/en-us/library/system.transactions.transactionscope.aspx I just want to confirm that is ...

System.Web.Mvc.Controller Initialize

i have the following base controller... public class BaseController : Controller { protected override void Initialize(System.Web.Routing.RequestContext requestContext) { if (...

Microsoft.Contracts namespace

For what it is necessary Microsoft.Contracts namespace in asp.net? I mean, in what cases I could write using Microsoft.Contracts;?

Separator line in ASP.NET

I d like to add a simple separator line in an aspx web form. Does anyone know how? It sounds easy enough, but still I can t manage to find how to do it.. 10x!

热门标签