[英]how to retrive data from the database based on a value of the cell of the datagridview
[英]How to retrive all types of data from sqlserver in datagridview on button click?
我想知道如何通过单击按钮从 DataGridView 中的 sqlserver 检索图像。 我可以使用以下代码显示其他类型的数据,并在图像列显示错误。 那么如何在按钮单击时在 DataGridView 中按列显示所有类型的数据,包括 c# 中的图像。
private void ViewButton_Click(object sender, EventArgs e)
{
SqlConnection connection = new SqlConnection("Data Source=DESKTOP-FQBMN3R\\SQLEXPRESS;Initial Catalog=StudentDB; Integrated Security=true");
connection.Open();
SqlDataAdapter sd = new SqlDataAdapter("select * from tbl_student_info", connection);
DataSet ds = new DataSet();
sd.Fill(ds, "tbl_student_info");
ViewDataGridView.DataSource = ds.Tables[0];
connection.Close();
}
SQL 数据类型image
在 c# 中作为byte[]
返回。 要将其转换为实际图像,您可以执行以下操作:
var imgArray = (byte[])ds.Tables[0].Rows[0]["FILE_IMAGE"];
using (var s = new MemoryStream(imgArray))
{
var img = System.Drawing.Image.FromStream(s);
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.