我必须将指纹模板存储在数据库中并检索它。 我必须将列名称设置为图像或var binary(max)吗? 我尝试了一些网站的一些代码,但没有奏效。存储和检索数据库中的二进制文件(fpt)
我从数据库中检索到一个空白文件。 正在使用SQL Server 2005 FTP文件是
在此先感谢1.59kb大小
//to add new user
public void AddUser(string name,byte[] pf,int length)
{
//code to insert file in database
cn = new SqlConnection(connstring);
cmd = new SqlCommand("adduser", cn);
cmd.CommandType = CommandType.StoredProcedure;
cmd.Parameters.AddWithValue("@name", name);
//to save converted image to variable
SqlParameter UploadedImage = new SqlParameter("@fp", SqlDbType.Binary, length);
UploadedImage.Value = pf;
cmd.Parameters.Add(UploadedImage);
cn.Open();
cmd.ExecuteNonQuery();
cn.Close();
}
//retrieve fingerprint from database
public void FingerPrintRtvl(string uid)
{
cn = new SqlConnection(connstring);
adp = new SqlDataAdapter("fingerprintrtvl", cn);
adp.SelectCommand.CommandType = CommandType.StoredProcedure;
adp.SelectCommand.Parameters.AddWithValue("@uid", Convert.ToInt32(uid));
DataSet ds = new DataSet("MyImages");
cn.Open();
adp.Fill(ds, "MyImages");
cn.Close();
byte[] MyData = new byte[57];
DataRow myRow;
myRow = ds.Tables["MyImages"].Rows[0];
MyData = (byte[])myRow["fp"];
int ArraySize = new int();
ArraySize = MyData.GetUpperBound(0);
string temp = System.IO.Path.GetTempPath();
string fpFile = "D:\\" + "fingerprint.fpt";
FileStream fs = new FileStream(fpFile, FileMode.OpenOrCreate, FileAccess.Write);
fs.Write(MyData, 0, ArraySize);
fs.Close();
}