MySQL只从数据库中获取Varchar

时间:2016-03-27 00:47:38

标签: mysql c#

我有一个看起来像MySql Datbase:

Item    CREATE TABLE `Item` (
        `ItemID` int(11) NOT NULL AUTO_INCREMENT,
        `ItemName` varchar(40) NOT NULL,
        `Description` varchar(500) NOT NULL,
        `Date` date NOT NULL,
        `Responsible` int(11) DEFAULT NULL,
        `Done` tinyint(1) NOT NULL DEFAULT '0',
        `Velocity` int(11) NOT NULL DEFAULT '0',
        `Inspector` int(11) DEFAULT NULL,
        `WorkbenchID` int(11) NOT NULL,
        UNIQUE KEY `PK` (`ItemID`),
        KEY `ItemID` (`ItemID`)
       ) ENGINE=InnoDB AUTO_INCREMENT=19 DEFAULT CHARSET=utf8

User    CREATE TABLE `User` (
        `UserID` int(11) NOT NULL AUTO_INCREMENT,
        `UserName` varchar(15) NOT NULL,
        UNIQUE KEY `PK` (`UserID`)
        ) ENGINE=InnoDB AUTO_INCREMENT=83 DEFAULT CHARSET=utf8
        UserInWorkbench CREATE TABLE `UserInWorkbench` (
       `WorkbenchID` int(9) NOT NULL,
       `UserID` int(9) NOT NULL,
        KEY `WorkbenchID` (`WorkbenchID`,`UserID`),
        KEY `UserID` (`UserID`),
        CONSTRAINT `UserInWorkbench_ibfk_2` FOREIGN KEY (`WorkbenchID`)                 
        REFERENCES `Workbench` (`WorkbenchID`) ON DELETE CASCADE ON UPDATE              
        CASCADE, CONSTRAINT `UserInWorkbench_ibfk_1` FOREIGN KEY (`UserID`)       
        REFERENCES `User` (`UserID`) ON DELETE CASCADE ON UPDATE CASCADE
        ) ENGINE=InnoDB DEFAULT CHARSET=utf8

Workbench   CREATE TABLE `Workbench` (
            `WorkbenchID` int(9) NOT NULL AUTO_INCREMENT,
            `WorkbenchName` varchar(20) NOT NULL,
            UNIQUE KEY `PK` (`WorkbenchID`)
            ) ENGINE=InnoDB AUTO_INCREMENT=16 DEFAULT CHARSET=utf8

我可以插入没有任何问题,我也可以获得Varchar值,但我不能得到任何其他数据类型,如Date Int等。

例如:

运行正常:

MySqlCommand getUser = new MySqlCommand("Select  ItemName From Item", connection);

但是这个:

MySqlCommand getUser = new MySqlCommand("Select  ItemID From Item", connection);

获取例外:

  

{“目标数组不足以复制集合中的所有项目。检查数组索引和长度。”} System.Exception {System.ArgumentException}

为什么我无法获得Int,Date等值?

0 个答案:

没有答案