asp.net js焦点图切换代码
能够从数据库读取图片。然后在前台显示。 请大哥大姐们 告诉我吧 也可以Hi我
追问:唉。是图片的显示切换啊
能够从数据库读取图片。然后在前台显示。 请大哥大姐们 告诉我吧 也可以Hi我
追问:唉。是图片的显示切换啊
答案://这个是上传
protected void Button2_Click(object sender, EventArgs e)
{
//得到用户要上传的文件名
string strFilePathName = UP_FILE.PostedFile.FileName;
string strFileName = Path.GetFileName(strFilePathName);
int FileLength = UP_FILE.PostedFile.ContentLength;
if (FileLength <= 0)
return;
try
{//上传文件
Byte[] FileByteArray = new Byte[FileLength]; //图象文件临时储存Byte数组
Stream StreamObject = UP_FILE.PostedFile.InputStream; //建立数据流对像
//读取图象文件数据,FileByteArray为数据储存体,0为数据指针位置、FileLnegth为数据长度
StreamObject.Read(FileByteArray, 0, FileLength);
//建立SQL Server链接
string strCon = WebConfigurationManager.ConnectionStrings["SqlConnectionStringHT"].ToString();
SqlConnection Con = new SqlConnection(strCon);
// String SqlCmd = "INSERT INTO ImageStore (ImageData, ImageContentType, ImageDescription, ImageSize) VALUES (@Image, @ContentType, @ImageDescription, @ImageSize)";
String SqlCmd = "INSERT INTO ImageStore (ImageData) VALUES (@Image)";
SqlCommand CmdObj = new SqlCommand(SqlCmd, Con);
CmdObj.Parameters.Add("@Image", SqlDbType.Binary, FileLength).Value = FileByteArray;
CmdObj.Parameters.Add("@ContentType", SqlDbType.VarChar, 50).Value = UP_FILE.PostedFile.ContentType; //记录文件类型
//把其它单表数据记录上传
CmdObj.Parameters.Add("@ImageDescription", SqlDbType.VarChar, 200).Value = txtDescription.Text;
//记录文件长度,读取时使用
CmdObj.Parameters.Add("@ImageSize", SqlDbType.BigInt, 8).Value = FileLength;
Con.Open();
CmdObj.ExecuteNonQuery();
Con.Close();
//跳转页面
Response.Redirect("ReadImage.aspx?id=1");
}
catch
{
}
}
//这个是读取
//从数据库中读取文件显示出来
private void ReadPicutre()
{
int ImgID = Convert.ToInt32(RadioButtonList1.SelectedValue);
//建立数据库链接
string strCon = WebConfigurationManager.ConnectionStrings["SqlConnectionStringHT"].ToString();
SqlConnection Con = new SqlConnection(strCon);
String SqlCmd = "SELECT * FROM ImageStore WHERE ImageID = @ImageID";
SqlCommand CmdObj = new SqlCommand(SqlCmd, Con);
CmdObj.Parameters.Add("@ImageID", SqlDbType.Int).Value = ImgID;
Con.Open();
SqlDataReader SqlReader = CmdObj.ExecuteReader();
SqlReader.Read();
// Response.ContentType = (string)SqlReader["ImageContentType"];//设定输出文件类型
//将文件保存到文件夹,然后在读取
string fileName = Server.MapPath(this.Request.ApplicationPath) + "\\" + ImgID + ".jpg";// + "\\1.jpg";
System.IO.File.WriteAllBytes(fileName, (byte[])SqlReader["ImageData"]);
this.Image1.ImageUrl = this.Request.ApplicationPath + "/" + ImgID + ".jpg";
//输出图象文件二进制数制
//Response.OutputStream.Write((byte[])SqlReader["ImageData"], 0, (int)SqlReader["ImageSize"]);
//Response.End();
//也可以保存为图像
// FileStream fs = new FileStream(@"C:\aa.BMP", FileMode.OpenOrCreate, FileAccess.Write);
// fs.Write((byte[])SqlReader["ImageData"], 0,(int)SqlReader["ImageSize"]);
// fs.Close();
Con.Close();
}
上一个:数据库配置文件 include/Dbpath.asp是什么意思怎么操作SQL2008的数据库??
下一个:我在86PS里的下的asp格式的笔刷,要放到PS哪个文件夹中才能使用啊