我正在尝试调整我使用FileUpload控件上传的jpg图像,并在将其保存到数据库(SQL Server 2008)之前将其转换为byte(varbinary(MAX)).我所做的和下面的代码显示我设法将其转换为字节并作为varbinary(MAX)保存到数据库中.我想知道如何在完成所有这些功能之前调整图像大小.帮帮我吧 谢谢!
阅读文件
string filePath = FileUpload1.PostedFile.FileName;
string filename = Path.GetFileName(filePath);
string ext = Path.GetExtension(filename);
Run Code Online (Sandbox Code Playgroud)
根据文件扩展名设置contenttype
string contenttype = String.Empty;
switch (ext)
{
case ".jpg":
contenttype = "image/jpg";
break;
}
Run Code Online (Sandbox Code Playgroud)
转换为字节并使用varbinary保存到数据库中
if (contenttype != String.Empty)
{
Stream fs = FileUpload1.PostedFile.InputStream;
BinaryReader br = new BinaryReader(fs);
Byte[] bytes = br.ReadBytes((Int32)fs.Length);
//insert the file into database
string strQuery = "insert into MemberReport(username, typeofcrime, location, crdatetime, citizenreport, image1, image2, image3, image4, image5)" +
" values ('" + username + "','" + …Run Code Online (Sandbox Code Playgroud) 我试图更新我的个人资料,但它在更新时不断捕获旧数据.可以做些什么来解决这个问题.请帮我解决这个问题谢谢!
protected void Page_Load(object sender, EventArgs e)
{
String nric = (String)Session["nric"];
SqlConnection con = new SqlConnection("Data Source = localhost; Initial Catalog = MajorProject; Integrated Security= SSPI");
con.Open();
SqlCommand cm = new SqlCommand("Select * from MemberAccount where nric = '" + nric + "'", con);
SqlDataReader dr;
dr = cm.ExecuteReader();
if (dr.Read())
{
txtFullName.Text = dr["fullname"].ToString();
txtAddress.Text = dr["address"].ToString();
txtContact.Text = dr["contact"].ToString();
txtEmail.Text = dr["email"].ToString();
}
con.Close();
}
protected void btnUpdate_Click(object sender, EventArgs e)
{
String nric = (String)Session["nric"];
if …Run Code Online (Sandbox Code Playgroud) 我Page_Load点击后试图调用方法btnSubmit.对于我,Page_Load我在dropdownlist框中的列上进行了数据绑定caseprogress != 'ongoing'.然后我为btnSubmit_Click我插入一些数据到另一个表,更新caseprogress = 'completed'和调用Page_Load方法.但我的下拉列表框似乎并不重新绑定.(除非我刷新页面)我尝试在其他页面上使用此方法,但不适用于此.仅供参考我在此页面中没有任何更新面板.同样适用于正在工作的另一个.
protected void Page_Load(object sender, EventArgs e)
{
if (!IsPostBack)
{
//Bind data to Dropdownlist box
}
}
protected void btnSubmit_Click(object sender, EventArgs e)
{
//Insert / Update data of sql data table
Page_Load(null, EventArgs.Empty);
}
Run Code Online (Sandbox Code Playgroud)