Click here to Skip to main content
15,887,421 members
Please Sign up or sign in to vote.
1.00/5 (3 votes)
See more:
I have code that previously worked, however, after editing some fields within the database, I now get a Type Mismatch at the Data Adapter Fill command.
C#
da.Fill(ds, "BundleInfo");

I have changed the field types in the database, and the format of some of the data, but it shouldn't affect the Fill command.
Field Type was Integer, now it is string
Same field used to hold data like: 1234 now might hold 1234U.

The SQL command (Really an Access DB, don't hate. :) ) is generated from:
C#
public string getBundleDesc(string BundleCode)
{
    //MessageBox.Show("Bundle Code = " + BundleCode);
    string select = "SELECT P.ProductCode, P.ProductName, P.ProductDescription,
        P.ListPrice, P.RecommendedPrice, P.MaxDiscount, P.PayStructure,
        P.ProductNotes, P.ProductType, B.BundleOrder, B.IncApp";
    string from = " FROM Bundle B";
    string innerJoin = " INNER JOIN Product P";
    string on = " ON B.ProductCode = P.ProductCode";
    string where = " WHERE B.BundleCode = " + BundleCode;
    string orderBy = " ORDER BY B.BundleOrder";
    return select + from + innerJoin + on + where + orderBy;
}

The only change in this command was the inclusion of B.IncApp in the Select statement.

The db structure is (Don't hate on the structure, I inherited it :) ):
Table
        Bundle
    Fields
        ID (PK, Auto)
        BundleCode (Short Text)
        ProductCode (Short Text)
        BundleOrder (Number)
        IncApp (Short Text)
Table
        Product
    Fields
        ID (PK, Auto)
        ProductCode (Short Text)
        ProductName (Short Text)
        ProductDescription (Long Text)
        ListPrice (Short Text)
        RecommendedPrice (Short Text)
        MaxDiscount (Short Text)
        PayStructure (Short Text)
        ProductNotes (Short Text)
        ProductType (Short Text)


The only changes to the DB structure are to Table -> Bundle -> BundleCode (Was Number, now a String) and the addition of the IncApp Field.

Updated the question with the information requested. Can someone point me in the right direction to fixing this?
Posted
Updated 17-Jan-16 16:25pm
v4
Comments
Dave Kreskowiak 17-Jan-16 17:39pm    
No, it doesn't have anything to do with the Fill method, but it may have everything to do with the SQL statement the DataAdapter was setup with. Too bad you didn't show that and what the new schema of the tables looks like.

Click on Improve question and fill in the missing detail.
KakitaIppatsu 17-Jan-16 22:25pm    
Updated the question with the requested info. Thanks for looking.

Bundle code in the where clause need to be surrounded with single quotes. The change from a number to text caused the type mismatch

SQL
string where = " WHERE B.BundleCode = '" + BundleCode + "'";
    string orderBy = " ORDER BY B.BundleOrder";
 
Share this answer
 
On top of what Mycroft said, Google for "C# parameterized queries" and start reading. Using string concatenation to build your SQL queries like this opens your code up to SQL Injection Attacks and the possible destruction of your database.
 
Share this answer
 
Comments
KakitaIppatsu 18-Jan-16 9:37am    
Thanks again for the help. I kept staring at it, knowing the problem, but not seeing it.

Dave, thanks for the input, this program is only used by one person. I'm just the lucky person who maintains it.
Dave Kreskowiak 18-Jan-16 15:43pm    
Keep in mind that not all sql injection attacks are initiated from outside the company and that not all attacks happen with intent to destroy. Some happen by accident and are initiated by employees.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900