如何向sql数据库中存取照片

来源:百度知道 编辑:UC知道 时间:2024/05/11 21:23:02

.net的:

private void btnUpload_Click(object sender, System.EventArgs e)
{
//得到用户要上传的文件名
string strFilePathName = loFile.PostedFile.FileName;
string strFileName = Path.GetFileName(strFilePathName);
int FileLength = loFile.PostedFile.ContentLength;
if(FileLength<=0)
return;
try
{//上传文件
Byte[] FileByteArray = new Byte[FileLength]; //图象文件临时储存Byte数组
Stream StreamObject = loFile.PostedFile.InputStream; //建立数据流对像
//读取图象文件数据,FileByteArray为数据储存体,0为数据指针位置、FileLnegth为数据长度
StreamObject.Read(FileByteArray,0,FileLength);
//建立SQL Server链接
string strCon = System.Configuration.ConfigurationSettings.AppSettings["DSN"];
SqlConnection Con = new SqlConnection(strCon);