程序中的赋值的四行有错,请高手指教!!!!!
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
}
}