SQL Server中的二进制文件 [英] binary file in sql server

查看:132
本文介绍了SQL Server中的二进制文件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

hai,
我如何在c#.net的sql server中存储和检索二进制文件(指纹模板文件)

hai,
how can i store and retrieve a binary file(fingerprint template file) in sql server in c#.net
thanks in advance!

推荐答案

希望对您有所帮助,

如何将二进制数据存储和提取到文件流列 [ ^ ]

:)
Hope it helps,

How to store and fetch binary data into a file stream column[^]

:)


尝试一下:

Save-and-Retrieve-Files- from-SQL-Server-Database-using-ASP.Net [
Try this:

Save-and-Retrieve-Files-from-SQL-Server-Database-using-ASP.Net[^]

hope it helps :)


在数据库中设置varbinary或image列.
然后将其插入:
Set up a varbinary or image column in your database.
Then just insert it:
using (SqlConnection con = new SqlConnection(strConnect))
    {
    con.Open();
    byte[] bytes = GetTheByteData();
    using (SqlCommand com = new SqlCommand("INSERT INTO myTable (myBinaryDataColumnName) VALUES (@BINDATA)", con))
        {
        com.Parameters.AddWithValue("@BINDATA", bytes);
        com.ExecuteNonQuery();
        }
    }



要提取它:



To extract it:

byte[] bytes;
using (SqlConnection con = new SqlConnection(strConnect))
    {
    con.Open();
    using (SqlCommand com = new SqlCommand("SELECT myBinaryDataColumnName FROM myTable", con))
        {
        using (SqlDataReader reader = com.ExecuteReader())
            {
            if (reader.Read())
                {
                bytes = (byte[]) reader["myBinaryDataColumnName"];
                }
            }
        }
    }

很显然,您将希望在SELECT语句上使用WHERE子句过滤返回的值,以仅检索您感兴趣的值.

Obviously, you will want to filter the returned values with a WHERE clause on the SELECT statement to just retrieve the one you are interested in.


这篇关于SQL Server中的二进制文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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