• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 799
  • Last Modified:

SQLDataSource Insert to Uniqueidentifier field error

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
krapvag
Asked:
krapvag
1 Solution
 
crazymanCommented:
try replacing the select * with the actual list of columns
0
 
krapvagAuthor Commented:
Tried that, same result
0
 
Jim P.Commented:
Try qualifying it a little more:

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

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

"SELECT * FROM [Server\instance].[DBname].[dbo].[vwTbl1]"
0
Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
Daniel WilsonCommented:
Try eliminating the CompanyID parameter from your insert command completely.  I think the DB wants to provide that.
0
 
krapvagAuthor Commented:
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
 
Daniel WilsonCommented:
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
 
krapvagAuthor Commented:
Yes, that seems to do it

Thanks a lot
0

Featured Post

Free Tool: SSL Checker

Scans your site and returns information about your SSL implementation and certificate. Helpful for debugging and validating your SSL configuration.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Tackle projects and never again get stuck behind a technical roadblock.
Join Now