我现在向数据库中存了一些图片但是我读取的时候只能读取9张图片 如果图片多了就读不出来 请问下是什么原因
下边是我读取数据库中数据的代码
SqlConnection conn = new SqlConnection("data source=192.168.0.199;initial catalog=HXTCYGL;uid=sa");
if (conn.State == ConnectionState.Open)
conn.Close();
string sql = "SELECT top 9 * FROM Mobile_XFXMML_PICTURE";
SqlCommand command = new SqlCommand(sql, conn);
try
{
conn.Open();
}
catch
{
MessageBox.Show(" 不能打开数据联接!");
}
SqlDataReader dr = command.ExecuteReader(); while (dr.Read())
{ byte[] mydata = ((byte[])dr["PICTURE"]); MemoryStream myStream = new MemoryStream(mydata);
Image myImage = Image.FromStream(myStream);
myStream.Close();
imageList1.Images.Add(myImage);
}
conn.Close();
lvImage.LargeImageList = imageList1; for (int i = 0; i < imageList1.Images.Count; i++)
{
ListViewItem item = new ListViewItem();
item.ImageIndex = i;
lvImage.Items.Add(item);
} lvImage是listView控件 imageList1是imageList控件
下边是我读取数据库中数据的代码
SqlConnection conn = new SqlConnection("data source=192.168.0.199;initial catalog=HXTCYGL;uid=sa");
if (conn.State == ConnectionState.Open)
conn.Close();
string sql = "SELECT top 9 * FROM Mobile_XFXMML_PICTURE";
SqlCommand command = new SqlCommand(sql, conn);
try
{
conn.Open();
}
catch
{
MessageBox.Show(" 不能打开数据联接!");
}
SqlDataReader dr = command.ExecuteReader(); while (dr.Read())
{ byte[] mydata = ((byte[])dr["PICTURE"]); MemoryStream myStream = new MemoryStream(mydata);
Image myImage = Image.FromStream(myStream);
myStream.Close();
imageList1.Images.Add(myImage);
}
conn.Close();
lvImage.LargeImageList = imageList1; for (int i = 0; i < imageList1.Images.Count; i++)
{
ListViewItem item = new ListViewItem();
item.ImageIndex = i;
lvImage.Items.Add(item);
} lvImage是listView控件 imageList1是imageList控件
因为你数据库里没数据,当然要报错啦。
继续改。
string sql = "SELECT * FROM Mobile_XFXMML_PICTURE where PICTURE is not null";