从数据库到图像控制的图像重建帮助我 [英] Retriving image from database to image control help me

查看:116
本文介绍了从数据库到图像控制的图像重建帮助我的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

图像以图像数据类型保存在数据库帮助我。

Image is saved in image datatype in database help me.

string sd = "select Name,Id,Designation,Phone,Address,Salary,Place,Image from Employee where Id='"+n+"'";
            SqlDataAdapter mad = new SqlDataAdapter(sd, DbConnection.mCon);
            DataTable dt3 = new DataTable();
            mad.Fill(dt3);
            if (dt3.Rows.Count > 0)
            {
                nam=dt3.Rows[0][0].ToString();
                id=int.Parse(dt3.Rows[0][1].ToString());
                desig = dt3.Rows[0][2].ToString();
                pho = dt3.Rows[0][3].ToString();
                addr = dt3.Rows[0][4].ToString();
                sal =float.Parse(dt3.Rows[0][5].ToString());
                plac = dt3.Rows[0][6].ToString();
                Image1.ImageUrl = dt3.Rows[0][7].ToString();
            }



以下编码是插入编码


the below coding is insertion coding

protected void Button1_Click(object sender, EventArgs e)
{
     img_upload = "~/img/" + FileUpload1.FileName;
     FileUpload1.SaveAs(MapPath(img_upload));
     Image1.ImageUrl = img_upload;
}
protected void Button2_Click(object sender, EventArgs e)
{
     string sm = "insert into Employee values('" + TextBox1.Text + "','" + TextBox2.Text + "','" + TextBox3.Text + "','" + TextBox4.Text + "','" + TextBox5.Text + "','" + TextBox6.Text + "','" + TextBox7.Text + "','"+img_upload+"')";
     SqlCommand cmdn = new SqlCommand(sm, DbConnection.mCon);
     cmdn.ExecuteNonQuery();
     Response.Write("<script>alert('Employee Details Inserted')</script>");
     TextBox1.Text = TextBox2.Text = TextBox3.Text =TextBox4.Text=TextBox5.Text=TextBox6.Text=TextBox7.Text= "";
     Image1.ImageUrl = null;
}

推荐答案

select Image from Employee where Id='yourID';



运行此查询在SSMS中,不是代码背后,看看它返回什么?复制结果并手动将图像URL设置为查询返回的结果。我确信路径没有在数据库中正确保存。还要检查您是否可以在img文件夹中看到保存的文件以及名称?


run this query in SSMS, not code behind and see what it returns? Copy the result and manually set the image URL to the result returned by your query. I am sure the path is not getting saved correctly in the database. Also check if you can see the saved file in you "img" folder and with what name?


这篇关于从数据库到图像控制的图像重建帮助我的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆