请给出相应的具体代码这是我写的代码,貌似不行:Image myImage = Image.FromFile(@"d:\metro.jpg");
System.Runtime.Serialization.Formatters.Binary.BinaryFormatter binaryFormatter = new System.Runtime.Serialization.Formatters.Binary.BinaryFormatter();
System.IO.MemoryStream memoryStream = new System.IO.MemoryStream();
binaryFormatter.Serialize(memoryStream, myImage);SqlConnection con = new SqlConnection(@"Data Source=NATTY-97FD32504\NATTY;Initial Catalog=test;Integrated Security=False;Connect Timeout=60;Application Name=MetroInfor;User ID=sa;Password=123456");
con.Open();
//INSERT INTO pic([text]) VALUES('1')
SqlCommand cmd = new SqlCommand("INSERT INTO pic([pic]) VALUES("+ myImage +")", con);
cmd.ExecuteNonQuery();con.Close();
System.Runtime.Serialization.Formatters.Binary.BinaryFormatter binaryFormatter = new System.Runtime.Serialization.Formatters.Binary.BinaryFormatter();
System.IO.MemoryStream memoryStream = new System.IO.MemoryStream();
binaryFormatter.Serialize(memoryStream, myImage);SqlConnection con = new SqlConnection(@"Data Source=NATTY-97FD32504\NATTY;Initial Catalog=test;Integrated Security=False;Connect Timeout=60;Application Name=MetroInfor;User ID=sa;Password=123456");
con.Open();
//INSERT INTO pic([text]) VALUES('1')
SqlCommand cmd = new SqlCommand("INSERT INTO pic([pic]) VALUES("+ myImage +")", con);
cmd.ExecuteNonQuery();con.Close();
用参数传递吧,存储过程也可以
//存图片
SqlCommand scom=new SqlCommand("insert into Photo values('"+ID+"',@ph)",scon);
FileStream fs=new FileStream(path,FileMode.Open,FileAccess.Read);
byte []bt=new byte[fs.Length];
fs.Read(bt,0,bt.Length);
fs.Close();
SqlParameter Spr=new SqlParameter("@ph",SqlDbType.Image,bt.Length,ParameterDirection.Input,
false,0,0,null,DataRowVersion.Current,bt);
scom.Parameters.Add(Spr);
scom.ExecuteNonQuery();//读图片SqlConnection conn=new SqlConnection(@"database....server...");
conn.Open();
SqlCommand cmd=new SqlCommand("select 照片 from fuser where password='1b'",conn);
SqlDataReader reader=cmd.ExecuteReader();
reader.Read();
MemoryStream buf=new MemoryStream((byte[])reader[0]);
Imageimage=Image.FromStream(buf,true);
pictureBox1.Image=image
反正我一只用这个方法,可以读写。不知道你行不行