使用Web服务将图像存储到数据库中 [英] storing an image into a database using webservice

查看:95
本文介绍了使用Web服务将图像存储到数据库中的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

您好,我目前正在从事一个项目,在这个项目中,我将从指纹读取器获取的指纹图像存储到数据库中.我也正在使用Web服务,并且从事此工作已经有相当长的时间了.如果有任何人可以提供帮助,我将不胜感激.我编写的代码写在下面,并且如果解决方案保持简单并进行解释,因为c#.thanks是我不熟悉的话,我也将不胜感激.
[代码]
[WebMethod]
公共布尔AddTemplate(byte [] template)

{
MySqlConnection conn =新的MySqlConnection(query);
MySqlCommand cmdInsert = null;
MySqlParameter dbParamInsert = null;
MySqlCommand cmdSelect = null;
GrFingerXCtrlClass gr =新的GrFingerXCtrlClass();
InitializeGrFinger(gr);
TTemplate tpt = new TTemplate();
//tpt._size = size;

int id;

试试
{

cmdInsert = new MySqlCommand("INSERT INTO medical_records(fingerprint)values(?)",conn);
//为?创建参数SQL语句中包含的内容.

//System.Byte [] temp =新的System.Byte [tpt._size +1];
//System.Array.Copy(tpt._tpt,0,template,0,tpt._size);
/* dbParamInsert = new MySqlParameter(?fingerprint",MySqlDbType.VarBinary,template.Count(),
ParameterDirection.Input,false,0、0,"ID",
DataRowVersion.Current,temp); */
dbParamInsert = new MySqlParameter("@ fingerprint",MySqlDbType.VarBinary,template.Count(),
ParameterDirection.Input,false,0、0,"id_no",
DataRowVersion.Current,模板);

cmdInsert.Parameters.Add(dbParamInsert);

//执行查询
如果(conn.State == ConnectionState.Open)
cmdInsert.ExecuteNonQuery();
}
赶上
{
返回false;
}
返回true;
}
[icode]

在客户端,我有
[代码]
公共int Enroll()
{
int id = 0;
//检查模板是否有效.
如果(TemplateIsValid())
{
//将模板添加到数据库并返回模板ID.
Service1SoapClient客户端=新的Service1SoapClient();
System.Byte []模板=新的System.Byte [_tpt._size +1];
System.Array.Copy(_tpt._tpt,0,template,0,_tpt._size);
//client.AddTemplate(template,ref id);
client.AddTemplate(template);

返回ID;

}
其他
{
返回-1;
}
}

[icode]

Hi,i m presently working on a project in which i am to store a fingerprint image gotten from a fingerprint reader into a database.I am using the web service too and i have been at this for a pretty long while.i ll be very grateful if theres anyone out there to help.the codes i wrote are written below and i ll also appreciate it if the solution is kept simple and explanations proffered because i m new to c#.thanks.
[code]
[WebMethod]
public bool AddTemplate(byte[] template)

{
MySqlConnection conn = new MySqlConnection(query);
MySqlCommand cmdInsert = null;
MySqlParameter dbParamInsert = null;
MySqlCommand cmdSelect = null;
GrFingerXCtrlClass gr = new GrFingerXCtrlClass();
InitializeGrFinger(gr);
TTemplate tpt = new TTemplate();
//tpt._size = size;

int id;

try
{

cmdInsert = new MySqlCommand("INSERT INTO medical_records(fingerprint) values(?) ", conn);
//Create parameter for ? contained in the SQL statement.

//System.Byte[] temp = new System.Byte[tpt._size + 1];
//System.Array.Copy(tpt._tpt,0,template,0,tpt._size);
/*dbParamInsert = new MySqlParameter("?fingerprint", MySqlDbType.VarBinary, template.Count(),
ParameterDirection.Input, false, 0, 0, "ID",
DataRowVersion.Current, temp);*/
dbParamInsert = new MySqlParameter("@fingerprint", MySqlDbType.VarBinary, template.Count(),
ParameterDirection.Input, false, 0, 0, "id_no",
DataRowVersion.Current, template);

cmdInsert.Parameters.Add(dbParamInsert);

//execute query
if (conn.State == ConnectionState.Open)
cmdInsert.ExecuteNonQuery();
}
catch
{
return false;
}
return true;
}
[icode]

on the client-side,i have
[code]
public int Enroll()
{
int id = 0;
// Checks if template is valid.
if (TemplateIsValid())
{
// Adds template to database and returns template ID.
Service1SoapClient client = new Service1SoapClient();
System.Byte[] template = new System.Byte[_tpt._size + 1];
System.Array.Copy(_tpt._tpt , 0,template,0,_tpt._size);
//client.AddTemplate(template,ref id);
client.AddTemplate(template);

return id;

}
else
{
return -1;
}
}

[icode]

推荐答案

看起来您已经有了代码.那您遇到错误了吗?
还是有一些您不理解的部分?

您能否详细说明问题,并指定确切的代码行?
Looks like you''ve already got the code. So are you getting an error?
Or is there some part of it that you don''t understand?

Could you mention your problem in a little more detail, with the exact lines of code specified, please?


问题是代码什么都不做.没有错误消息,并且没有添加模板进入数据库.它什么也没有做!如果您能提供帮助,我将不胜感激.谢谢.
The problem is that the code does nothing.no error messages and it doesnt add the template into the database.it just does nothing!i will appreciate it if you can be of help.thank you.


这篇关于使用Web服务将图像存储到数据库中的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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