0
嗨,朋友,我已经插入图像到Sql Server,我需要检索图像从SQL Server 2008 R2到Datagridview列在C#[Windows应用程序]。是否有可能在数据网格视图中显示图像是网格视图列中的任何相应大小。如何检索从SQL Server 2008 R2到Datagridview在C#中的图像[Windows应用程序]
我的编码插入图像到SQL Server是:
public void saveImageInDataBase(int imageid)
{
byte[] imagedata = ReadImageFile(txt_upload.Text);
SqlConnection sqlconn = new SqlConnection();
sqlconn.ConnectionString = "Data Source=.;Initial Catalog=db_payroll;Integrated Security=True;";
sqlconn.Open();
string query = "insert into tbl_image values('"+imagedata+"')";
MessageBox.Show(query);
SqlCommand cmd = new SqlCommand(query, sqlconn);
int rows = cmd.ExecuteNonQuery();
if (rows > 0)
{
MessageBox.Show("Image saved.");
txt_upload.Text = "";
pictureBox1.Image = null;
}
else
{
MessageBox.Show("Unable to save image.");
sqlconn.Close();
}
}
public byte[] ReadImageFile(string imageLocation)
{
byte[] imageData = null;
FileInfo fileInfo = new FileInfo(imageLocation);
long imageFileLength = fileInfo.Length;
FileStream fs = new FileStream(imageLocation, FileMode.Open, FileAccess.Read);
BinaryReader br = new BinaryReader(fs);
imageData = br.ReadBytes((int)imageFileLength);
return imageData;
}
请尝试解决这个问题。由于
其作品很好...你能告诉我,如何将单元格大小修改为100 X 100,图像样式应该像拉伸一样。 – coolprarun 2013-02-16 14:41:52
@coolprarun为此,您可以使用'Ask Question'按钮并使用适当的标题创建新线程。 – 2013-02-16 14:55:23