SqlServer数据库中字段类型与 C#中类型的对应

1.SqlServer中的字段类型 整形有 bigint  int  smallint  tinyint

从大到小依次为:

bigint

从 -2^63 (-9223372036854775808) 到 2^63-1(9223372036854775807) 的整型数据

(所有数字)。存储大小为 8 个字节

int

从 -2^31 (-2,147,483,648) 到 2^31 - 1(  21亿左右 够用了 ) 的整型数据(所有数字)。

存储大小为 4 个字节。int 的 SQL-92 同义字为 integer。

smallint

从 -2^15 (-32,768) 到 2^15 - 1 ( 3万左右够用了 ) 的整型数据。存储大小为 2 个字节

tinyint

从 0 到 255 的整型数据。存储大小为 1 字节

其中查询行号RowNum是 bigint   ,c#中可用 int64 或 long 接收。

查询记录数是 int  , c#中用 int 或 int32 接收。

2.与C#类型对应关系如下:

序号

类别

SQLServer

C Sharp

备注

1

整数

bit

Boolean

True转换为1False转换为0

2

tinyint

Byte

C Sharp 数据类型都位于System命名空间

3

smallint

Int16

4

int

Int32

5

bigint

Int64

6

smallmoney

Decimal

7

money

Decimal

8

numeric

Decimal

9

decimal

Decimal

10

浮点数

float

Double

11

real

Single

12

日期和时间

smalldatetime

DateTime

13

datetime

DateTime

14

timestamp

DateTime

15

字符串

char

String

16

text

String

17

varchar

String

18

nchar

String

19

ntext

String

20

nvarchar

String

21

二进制数据

 

 

binary

Byte[]

22

varbinary

Byte[]

23

image

Byte[]

24

其他

uniqueidentifier

Guid

25

Variant

Object

查看原网址: https://www.cnblogs.com/coce/p/9070961.html

 

 

 

  • 2
    点赞
  • 8
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
要在 C# 窗体程序从 MySQL 数据库下载文件,可以采用以下步骤: 1. 首先,需要在 MySQL 数据库创建一个 BLOB 字段,并将文件存储在该字段。 2. 在 C# 窗体程序,需要使用 MySQL 数据库连接库和命令库来连接 MySQL 数据库,并执行 SQL 查询语句,以获取包含文件内容的 BLOB 字段。 3. 将 BLOB 数据转换为 byte[] 数组,并将其写入磁盘上的文件。 下面是一个示例代码,演示如何从 MySQL 数据库下载文件: ```c# using System; using System.Data; using System.IO; using System.Windows.Forms; using MySql.Data.MySqlClient; namespace DownloadFileFromMySQL { public partial class Form1 : Form { private MySqlConnection connection; private MySqlCommand command; public Form1() { InitializeComponent(); } private void button1_Click(object sender, EventArgs e) { // 连接 MySQL 数据库 connection = new MySqlConnection("server=localhost;database=test;uid=root;pwd=123456;"); connection.Open(); // 查询包含文件内容的 BLOB 字段 command = new MySqlCommand("SELECT file_content FROM files WHERE file_name=@name", connection); command.Parameters.AddWithValue("@name", "test.txt"); MySqlDataReader reader = command.ExecuteReader(); if (reader.Read()) { // 将 BLOB 数据转换为 byte[] 数组,并将其写入磁盘上的文件 byte[] fileData = (byte[])reader["file_content"]; File.WriteAllBytes("test.txt", fileData); MessageBox.Show("Download completed!"); } else { MessageBox.Show("File not found!"); } reader.Close(); connection.Close(); } } } ``` 以上代码,假设在 MySQL 数据库已经创建了一个名为 `files` 的表,其包含两个字段 `file_name` 和 `file_content`,`file_content` 字段为 BLOB 类型。下载文件时,根据文件名查询对应的 BLOB 数据,并将其写入磁盘上的文件

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值