OleDB da.Fill命令提供类型不匹配错误 [英] OleDB da.Fill Command gives Type Mismatch error

查看:48
本文介绍了OleDB da.Fill命令提供类型不匹配错误的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有以前工作过的代码,但是,在编辑了数据库中的某些字段后,我现在在Data Adapter Fill命令中得到了Type Mismatch。

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.

da.Fill(ds, "BundleInfo");



我已经更改了数据库中的字段类型,以及某些数据的格式,但它不应该影响Fill命令。

字段类型是整数,现在是字符串

用于保存数据的相同字段:1234现在可能容纳1234U。



SQL命令(真的是Access DB,不要讨厌。:))生成自:


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:

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;
}



此命令的唯一变化是在Select语句中包含B.IncApp。



数据库结构是(不要讨厌结构,我继承它:)):


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)





DB结构的唯一变化是Table - >捆绑 - > BundleCode(数字,现在是一个字符串)和IncApp字段的添加。



使用所需信息更新了问题。有人能指出我正确的方向来解决这个问题吗?



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?

推荐答案

where子句中的bundle代码需要用单引号括起来。从数字到文本的更改导致类型不匹配



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

string where = " WHERE B.BundleCode = '" + BundleCode + "'";
    string orderBy = " ORDER BY B.BundleOrder";


除了Mycroft所说的,谷歌的C#参数化查询并开始阅读。使用字符串连接来构建这样的SQL查询会打开您的代码,直到SQL注入攻击和可能的数据库破坏。
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.


这篇关于OleDB da.Fill命令提供类型不匹配错误的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆