标题:图片存入数据库的问题
只看楼主
wwpewr
Rank: 1
等 级:新手上路
帖 子:6
专家分:0
注 册:2006-4-18
 问题点数:0 回复次数:2 
图片存入数据库的问题

程序中的赋值的四行有错,请高手指教!!!!!
using System;
using System.Collections;
using System.ComponentModel;
using System.Data;
using System.Data.SqlClient;
using System.Drawing;
using System.IO;
using System.Web;
using System.Web.SessionState;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.HtmlControls;

namespace ImageStorage
{
/// <summary>
/// Summary description for UploadImage.
/// </summary>
public class UploadImage : System.Web.UI.Page
{
//HtmlControl、WebControls控件对象
protected System.Web.UI.HtmlControls.HtmlInputFile UP_FILE;
protected System.Web.UI.WebControls.TextBox txtDescription;
protected System.Web.UI.WebControls.Label txtMessage;
protected System.Web.UI.WebControls.Button Button1;

protected Int32 FileLength = 0; //记录文件长度变量

protected void Button_Submit(System.Object sender, System.EventArgs e)
{
//HttpPostedFile对象,用于读取图象文件属性
HttpPostedFile UpFile = UP_FILE.PostedFile;
//记录文件长度
FileLength = UpFile.ContentLength;
try
{
if (FileLength == 0)
{
//文件长度为零时
txtMessage.Text = "<b>请你选择你要上传的文件</b>";
}
else
{
Byte[] FileByteArray = new Byte[FileLength]; //图象文件临时储存Byte数组
Stream StreamObject = UpFile.InputStream; //建立数据流对像
//读取图象文件数据,FileByteArray为数据储存体,0为数据指针位置、FileLnegth为数据长度
StreamObject.Read(FileByteArray,0,FileLength);
//建立SQL Server链接
SqlConnection Con = new SqlConnection("Data Source=Localhost;Initial Catalog=StudyImage;User ID=sa;Pwd=sa;");
String SqlCmd = "INSERT INTO ImageStore (ImageData, ImageContentType, ImageDescription, ImageSize) valueS (@Image, @ContentType, @ImageDescription, @ImageSize)";
SqlCommand CmdObj = new SqlCommand(SqlCmd, Con);
/*****************************下面四行赋值的语句出错****************************************/
/*****************************编译时报的错误见下一行****************************************/
/***error CS0117: 'System.Data.SqlClient.SqlParameter' does not contain a definition for 'value'************/
/***************************请高手指教一下,如何修改***************************************/
CmdObj.Parameters.Add("@Image",SqlDbType.Binary, FileLength).value = FileByteArray;
//记录文件类型
CmdObj.Parameters.Add("@ContentType", SqlDbType.VarChar,50).value = UpFile.ContentType;
//把其它单表数据记录上传
CmdObj.Parameters.Add("@ImageDescription", SqlDbType.VarChar,200).value = txtDescription.Text;
//记录文件长度,读取时使用
CmdObj.Parameters.Add("@ImageSize", SqlDbType.BigInt,8).value = UpFile.ContentLength;
Con.Open();
CmdObj.ExecuteNonQuery();
Con.Close();
//提示上传成功
txtMessage.Text = "<p><b>OK!你已经成功上传你的图片</b>";
}
}
catch (Exception ex)
{
txtMessage.Text = ex.Message.ToString();
}
}


private void Page_Load(object sender, System.EventArgs e)
{
// Put user code to initialize the page here
}

#region Web Form Designer generated code
override protected void OnInit(EventArgs e)
{
//
// CODEGEN: This call is required by the ASP.NET Web Form Designer.
//
InitializeComponent();
base.OnInit(e);
}

/// <summary>
/// Required method for Designer support - do not modify
/// the contents of this method with the code editor.
/// </summary>
private void InitializeComponent()
{
this.Load += new System.EventHandler(this.Page_Load);
}
#endregion
}
}

搜索更多相关主题的帖子: using System 数据库 Web summa 
2006-08-08 09:17
chenjin145
Rank: 1
等 级:禁止访问
帖 子:3922
专家分:0
注 册:2006-7-12
得分:0 
value小寫了

Value

[url=javascript:alert(1);] [div]fdgfdgfdg\" on\"[/div] [/url]
2006-08-08 09:27
wwpewr
Rank: 1
等 级:新手上路
帖 子:6
专家分:0
注 册:2006-4-18
得分:0 
3Q
2006-08-08 09:37



参与讨论请移步原网站贴子:https://bbs.bccn.net/thread-82715-1-1.html




关于我们 | 广告合作 | 编程中国 | 清除Cookies | TOP | 手机版

编程中国 版权所有,并保留所有权利。
Powered by Discuz, Processed in 0.024391 second(s), 7 queries.
Copyright©2004-2024, BCCN.NET, All Rights Reserved