gpt4 book ai didi

mysql - 为什么 MySQL 查询在 VB.net 中将整数列读取为字节数组?

转载 作者:行者123 更新时间:2023-11-29 00:24:12 25 4
gpt4 key购买 nike

我有一个简单的 MySQL 表,其中包含一个带有整数值和空值的“Age”列。

    Customers
+--------------+--------------+ .... +------------+
| Name | Location | | Age |
+--------------+--------------+ .... +------------+
| Murphy | US | | 23 |
| Pierre | France | | 42 |
| Rafael | Spain | | null |
| Paulo | Italy | | 21 |
+--------------+--------------+ .... +------------+

姓名和位置是 varChar 类型,年龄是 int 类型。

但是,当我尝试在我的 VB.net 代码中读取它时...

Dim connStr as string = Session("connectionString") 'My Connection String'
Dim sql As String = "SELECT * FROM Customers;"
Dim conn As MySqlConnection = New MySqlConnection(connStr)
conn.Open()
Dim da As MySqlDataAdapter = New MySqlDataAdapter(sql , conn)
Dim ds as new dataset
da.Fill(ds)

...数据集 ds 中的 Age 列在每个单元格中都有 System.Byte[] 而不是整数值。

为什么会这样?

最佳答案

尽量确保 Age 列只返回整数值。

将您的选择更改为

SELECT Name,Location,IFNULL(Age,0) AS Age FROM Customers;

再检查一下,您的数据集是否允许 dbnull?您可以更改一个属性。也许也可以尝试使用您的初始 SELECT * FROM Customers;

关于mysql - 为什么 MySQL 查询在 VB.net 中将整数列读取为字节数组?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/19792170/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com