Solved

SQLDataSource Insert to Uniqueidentifier field error

Posted on 2008-10-21
7
786 Views
Last Modified: 2012-05-05
Hi,

I have been given a database to build a front end to.

I have a Company table that is a lookup table, and the ID of each record is a UniqueIdentifier object.  The table I am inserting into has a reference to the company table, and that column is also a uniqueidentifier

For the front end I have a SQLDataSource insert method that is called by clicking a button.

When it goes to run the Insert() function, I get the error: No mapping exists from DbType Object to a known OdbcType.

I've searched for this on Google and it tells me that my SELECT querystring is incorrect.  But all it is is "SELECT * FROM [view]"

When run the select query, it returns all data OK
/*C# code*/

    protected void lkbAddTariff_Click(object sender, EventArgs e)

    {

        DropDownList dCompany = gvTariff.FooterRow.FindControl("dlCompany") as DropDownList;

        TextBox tTarName = gvTariff.FooterRow.FindControl("txtTarName") as TextBox;

        TextBox tThreshold = gvTariff.FooterRow.FindControl("txtThreshold") as TextBox;

        TextBox tDirection = gvTariff.FooterRow.FindControl("txtDirection") as TextBox;

        TextBox tInaTar = gvTariff.FooterRow.FindControl("txtInaTariff") as TextBox;

        TextBox tCrossband = gvTariff.FooterRow.FindControl("txtCrossband") as TextBox;

 

        dsTariff.InsertParameters["ta_name"].DefaultValue = tTarName.Text;

        dsTariff.InsertParameters["ta_crossband"].DefaultValue = tCrossband.Text;

        dsTariff.InsertParameters["ta_thresholdDays"].DefaultValue = tThreshold.Text;

        dsTariff.InsertParameters["CompanyID"].DefaultValue = dCompany.SelectedValue;

        dsTariff.InsertParameters["INA_Tariff"].DefaultValue = tInaTar.Text;

        dsTariff.InsertParameters["Direction"].DefaultValue = tDirection.Text;

 

 

        dsTariff.Insert();

        gvTariff.DataSourceID = "dsTariff";

 

        gvTariff.DataBind();

    }

 

 

 

ASP.NET Code

 

 

 

<asp:SqlDataSource ID="dsTariff" runat="server" ConnectionString="<%$ ConnectionStrings:iceConnectionString %>" 

    InsertCommand="INSERT INTO [tbl1] ([ta_name], [ta_crossband], [ta_thresholdDays], [CompanyID], [INA_Tariff], [Direction]) VALUES (?, ?, ?, ?, ?, ?)" OldValuesParameterFormatString="original_{0}" ProviderName="<%$ ConnectionStrings:ConnectionString.ProviderName %>" 

    SelectCommand="SELECT * FROM [vwTbl1]" >

        <InsertParameters>

            <asp:Parameter Name="ta_name" Type="String" />

            <asp:Parameter Name="ta_crossband" Type="Int32" />

            <asp:Parameter Name="ta_thresholdDays" Type="Int32" />

            <asp:Parameter Name="CompanyID" Type="Object" />

            <asp:Parameter Name="INA_Tariff" Type="Int32" />

            <asp:Parameter Name="Direction" Type="String" />

        </InsertParameters>

    </asp:SqlDataSource>

Open in new window

0
Comment
Question by:krapvag
7 Comments
 
LVL 13

Expert Comment

by:crazyman
ID: 22765652
try replacing the select * with the actual list of columns
0
 
LVL 1

Author Comment

by:krapvag
ID: 22765686
Tried that, same result
0
 
LVL 38

Expert Comment

by:Jim P.
ID: 22786950
Try qualifying it a little more:

"SELECT * FROM [dbo].[vwTbl1]"

"SELECT * FROM [DBname].[dbo].[vwTbl1]"

"SELECT * FROM [Server\instance].[DBname].[dbo].[vwTbl1]"
0
Threat Intelligence Starter Resources

Integrating threat intelligence can be challenging, and not all companies are ready. These resources can help you build awareness and prepare for defense.

 
LVL 32

Expert Comment

by:Daniel Wilson
ID: 22788330
Try eliminating the CompanyID parameter from your insert command completely.  I think the DB wants to provide that.
0
 
LVL 1

Author Comment

by:krapvag
ID: 22797933
Hi All,

Thank you all for your suggestions. Unfortunately I still could not add data to this field.  It is a Foreign Key field, so we should already have the uniqueID (therefore we cannot simply do NewID())

0
 
LVL 32

Accepted Solution

by:
Daniel Wilson earned 500 total points
ID: 22798536
The underlying DB data type is UniqueIdentifier, right?

Would you switch your parameter from type Object to Guid ?
http://msdn.microsoft.com/en-us/library/cc668759.aspx
0
 
LVL 1

Author Closing Comment

by:krapvag
ID: 31508194
Yes, that seems to do it

Thanks a lot
0

Featured Post

PRTG Network Monitor: Intuitive Network Monitoring

Network Monitoring is essential to ensure that computer systems and network devices are running. Use PRTG to monitor LANs, servers, websites, applications and devices, bandwidth, virtual environments, remote systems, IoT, and many more. PRTG is easy to set up & use.

Join & Write a Comment

When you hear the word proxy, you may become apprehensive. This article will help you to understand Proxy and when it is useful. Let's talk Proxy for SQL Server. (Not in terms of Internet access.) Typically, you'll run into this type of problem w…
Introduction In my previous article (http://www.experts-exchange.com/Microsoft/Development/MS-SQL-Server/SSIS/A_9150-Loading-XML-Using-SSIS.html) I showed you how the XML Source component can be used to load XML files into a SQL Server database, us…
Familiarize people with the process of utilizing SQL Server functions from within Microsoft Access. Microsoft Access is a very powerful client/server development tool. One of the SQL Server objects that you can interact with from within Microsoft Ac…
Viewers will learn how to use the SELECT statement in SQL and will be exposed to the many uses the SELECT statement has.

758 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

22 Experts available now in Live!

Get 1:1 Help Now