问题描述
SqlConnection con = new SqlConnection();
con.ConnectionString = "Data Source=PROMOD-PC;Initial Catalog=travel_Directions;Integrated Security=True";
DataTable dt = new DataTable();
String selQuery = "SELECT Image FROM MapDataImage WHERE Source='" + TextBox1.Text + "';";
SqlCommand SelCmmnd = new SqlCommand(selQuery,con);
SqlDataReader sDatAdp = new SqlDataReader();
con.Open();
sDatAdp = SelCmmnd.ExecuteReader();
byte[] imagedb = (byte[])(sDatAdp["Image"]);
//SelCmmnd.CommandType = CommandType.Text;
//SelCmmnd.Connection = con;
MemoryStream mymemstr = new MemoryStream(imagedb);
//SelCmmnd.ExecuteScalar();
//sDatAdp.SelectCommand = SelCmmnd;
//sDatAdp.Fill(imagedb);
ListView1.DataSource = imagedb;
ListView1.DataBind();
con.Close();
//sDatAdp.Dispose();
con.Dispose();
i也为检索图像制作了此代码。
但这不起作用
................
查看此代码,请有人帮助我!!!
i have made this code for retrieve image as well.
but this is not working
................
check this code and Please someone help me!!!
推荐答案
- 请调试并查看问题所在。
- 确保
ConnectionString
是正确的。
您可以参考 []
- 在下面的行中,您尝试将图像直接绑定到
DataSource
。
- Please debug and see what is the problem.
- Make sure the
ConnectionString
is correct.
You can refer http://www.connectionstrings.com/[^] - In below line, you are trying to bind the image directly to
DataSource
.
ListView1.DataSource = imagedb;
相反,你应该指定一个 DataTable
或 DataSet
并填充 DataTable
或 DataSet
SqlDataAdapter
class。
参考 - []
Instead you should assign a DataTable
or DataSet
and populate that DataTable
or DataSet
via SqlDataAdapter
class.
Refer - [MSDN] BaseDataBoundControl.DataSource Property[^]
while (reader.Read())
{
Console.WriteLine(String.Format("{0}", reader[0]));
}
参考 - []
Refer - [MSDN] SqlCommand.ExecuteReader Method [^]
但我相信如果你会遵循我的第一个建议,你会发现你的问题。
如果你发现确切的问题,那么你实际上可以解决它。
But I am sure that if you will follow my first suggestion,. you will find your problem.
If you find the exact problem, then you can actually solve it.
这篇关于检索binaryimage sql数据到ListView的方法..?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!