在数据库C#中存储图像

时间:2015-11-08 07:30:23

标签: c# sql database

我在将图像保存到mediumblob(数据库)时遇到问题。我只是想知道为什么当我查看我的返回时,我要保存的图片目录是完整的C:\\Users\\Public\\Pictures\\Sample Pictures\\Hydrangeas.jpg

将其存储到mediumblobs(在数据库中)后,C:UsersPublicPicturesSample PicturesHydrangeas.jpg \\将其存储到数据库后消失。

到目前为止,这是我的代码:

OpenFileDialog open = new OpenFileDialog();          
open.Filter = "Image Files(*.jpg; *.jpeg; *.gif; *.bmp)|*.jpg; *.jpeg; *.gif; *.bmp";

if (open.ShowDialog() == DialogResult.OK)
{
    pictureBox2.Image = new Bitmap(open.FileName);
    images = open.FileName;
}

图像包含字符串的目录。

这是用于插入

public void NewEmployee(Employee employee)
{
    OdbcConnection con = new OdbcConnection();
    con.ConnectionString = MyConnectionString;

    con.Open();

    OdbcCommand cmd = new OdbcCommand("insert into Employee_Tbl(Employee_No,Emp_Lastname,Emp_FirstName,Emp_MI,Emp_Position,Emp_Username,Emp_Password,Emp_Image) values ('" + employee.EmployeeID + "','" + employee.LastName + "','" + employee.FirstName + "','" + employee.MI + "','" + employee.Position + "','" + employee.Username + "','" + employee.Password + "','" + employee.Image + "') ", con);
    cmd.CommandType = CommandType.Text;
    cmd.ExecuteNonQuery();
}

0 个答案:

没有答案