public static SqlConnection connection = new SqlConnection("server=.; database=FilmDirectory; Integrated Security=true"); public static Bitmap GetPicture(int i)
{
byte[] imageByte = null; string sql = "select Image from film where ID=" + i;
connection.Open();
SqlCommand cmd = new SqlCommand();
cmd.CommandType = CommandType.Text;
cmd.CommandText = sql;
cmd.Connection = connection; SqlDataReader dr = cmd.ExecuteReader();
while (dr.Read())
{
imageByte = (byte[])dr[0];
} dr.Close();
connection.Close();
MemoryStream ms = new MemoryStream(imageByte, true);
Bitmap bmpt = new Bitmap(ms);
return bmpt;
}
这段代码中老是出现“参数无效”的错误。错误指向红色部分,不知何解。请赐教!-----------------------------------------------------------------------------------------
public static SqlConnection connection = new SqlConnection("server=.; database=FilmDirectory; Integrated Security=true");.................
string sqlStr = "select top 3 * from film";
DataSet ds = new DataSet();
ds = GetDataFromDB(sqlStr);
if (ds != null)
{
for (int i = 1; i <= ds.Tables[0].Rows.Count; i++)
{
switch (i)
{
case 1:
................
pictureBox1.Image = Image.FromStream(new MemoryStream((byte[])(ds.Tables[0].Rows[0].ItemArray[7])));
break;这是用DataSet数据集的方式访问数据库,但是还是会出现相同的错误。高手们请赐教!
{
byte[] imageByte = null; string sql = "select Image from film where ID=" + i;
connection.Open();
SqlCommand cmd = new SqlCommand();
cmd.CommandType = CommandType.Text;
cmd.CommandText = sql;
cmd.Connection = connection; SqlDataReader dr = cmd.ExecuteReader();
while (dr.Read())
{
imageByte = (byte[])dr[0];
} dr.Close();
connection.Close();
MemoryStream ms = new MemoryStream(imageByte, true);
Bitmap bmpt = new Bitmap(ms);
return bmpt;
}
这段代码中老是出现“参数无效”的错误。错误指向红色部分,不知何解。请赐教!-----------------------------------------------------------------------------------------
public static SqlConnection connection = new SqlConnection("server=.; database=FilmDirectory; Integrated Security=true");.................
string sqlStr = "select top 3 * from film";
DataSet ds = new DataSet();
ds = GetDataFromDB(sqlStr);
if (ds != null)
{
for (int i = 1; i <= ds.Tables[0].Rows.Count; i++)
{
switch (i)
{
case 1:
................
pictureBox1.Image = Image.FromStream(new MemoryStream((byte[])(ds.Tables[0].Rows[0].ItemArray[7])));
break;这是用DataSet数据集的方式访问数据库,但是还是会出现相同的错误。高手们请赐教!
obj=数据库读取的二进制数据; Byte[] byt = new Byte[0];
byt = (Byte[])(obj);
System.IO.MemoryStream stm = new System.IO.MemoryStream(byt);
System.Drawing.Image image = System.Drawing.Image.FromStream(stm);
Image image=Image.FromStream(ms,true);
picturebox1.Image=image;
检查数据长度