1.建立一aspx页面,html代码2.cs代码
using System.Data.SqlClient;
using System.IO;
protected void Page_Load(object sender, EventArgs e)
{
if (!Page.IsPostBack)
{
BindData();
}
if (ID != "")
{
GetDescriptionByID(ID);
}
}
property#region property
private string ID
{
get
{
if (Request["ID"] != null && Request["ID"].ToString() != "")
{
return Request["ID"];
}
else
{
return "";
}
}
}
#endregion
GetDescriptionByID#region GetDescriptionByID
private void GetDescriptionByID(string ID)
{
string connStr = ConfigurationSettings.AppSettings["ConnectionString"];
SqlConnection conn = new SqlConnection(connStr);
string sql = "select * from testimage where userid='" + ID + "'";
SqlCommand cmd = new SqlCommand(sql, conn);
conn.Open();
SqlDataReader dr = cmd.ExecuteReader();
string s = @"<table cellspacing='0' cellpadding='4' width='300' height='200' border='0' id='GridView1' style='color:#333333;border-collapse:collapse;'>";
if(dr.Read())
{
s += "<tr style='color:#333333;background-color:#FFFBD6;'>";
s += "<td width='50'>名称:</td>";
s += "<td>" + dr["UserName"] + "</td>";
s += "</tr>";
s += "<tr style='color:#333333;background-color:White;'>";
s += "<td scope='col'>描述:</td>";
s += "<td>" + dr["Description"] + "</td>";
s += "</tr>";
}
s += "</table>";
dr.Close();
conn.Close();
this.Response.Write(s);
this.Response.End();
}
#endregion
save image#region save image
protected void Button2_Click(object sender, EventArgs e)
{
Stream ImageStream;
string Path = FileUpload1.PostedFile.FileName;// 文件名称
int Size = FileUpload1.PostedFile.ContentLength; // 文件大小
string Type = FileUpload1.PostedFile.ContentType; // 文件类型
ImageStream = FileUpload1.PostedFile.InputStream;
byte[] Content = new byte[Size];
int Status = ImageStream.Read(Content, 0, Size);
SqlConnection conn = new SqlConnection(ConfigurationSettings.AppSettings["ConnectionString"]);
Tags:动态 实现 ID string SqlConnection if new td 文件 conn