?
Solved

SQLDataSource Insert to Uniqueidentifier field error

Posted on 2008-10-21
7
Medium Priority
?
792 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
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
Get 15 Days FREE Full-Featured Trial

Benefit from a mission critical IT monitoring with Monitis Premium or get it FREE for your entry level monitoring needs.
-Over 200,000 users
-More than 300,000 websites monitored
-Used in 197 countries
-Recommended by 98% of users

 
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 1500 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

Free Tool: Subnet Calculator

The subnet calculator helps you design networks by taking an IP address and network mask and returning information such as network, broadcast address, and host range.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Ever needed a SQL 2008 Database replicated/mirrored/log shipped on another server but you can't take the downtime inflicted by initial snapshot or disconnect while T-logs are restored or mirror applied? You can use SQL Server Initialize from Backup…
In the first part of this tutorial we will cover the prerequisites for installing SQL Server vNext on Linux.
This videos aims to give the viewer a basic demonstration of how a user can query current session information by using the SYS_CONTEXT function
Using examples as well as descriptions, and references to Books Online, show the documentation available for datatypes, explain the available data types and show how data can be passed into and out of variables.
Suggested Courses

752 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