look ! SqlConnection cn = new SqlConnection(this.sqlstring); //int pub_id=2003; SqlCommand cmd = new SqlCommand("INSERT INTO images (images_id, logo) VALUES (2003,@BLOBData)", cn); String strBLOBFilePath = @"C:/picture/bt1.jpg";//Modify this path as needed. //Read jpg into file stream, and from there into Byte array. FileStream fsBLOBFile = new FileStream(strBLOBFilePath,FileMode.Open, FileAccess.Read); Byte[] bytBLOBData = new Byte[fsBLOBFile.Length]; fsBLOBFile.Read(bytBLOBData, 0, bytBLOBData.Length); fsBLOBFile.Close(); //Create parameter for insert command and add to SqlCommand object. SqlParameter prm = new SqlParameter("@BLOBData", SqlDbType.VarBinary, bytBLOBData.Length, ParameterDirection.Input, false, 0, 0, null, DataRowVersion.Current, bytBLOBData); cmd.Parameters.Add(prm); //Open connection, execute query, and close connection. cn.Open(); cmd.ExecuteNonQuery(); cn.Close();
to smiletosky,烟鬼: 谢谢你们的连接,我会看的。 to乡村酒吧: Sqlserver2000 to神农无忌: 谢谢你的代码。我现在试一试。 感谢各位关心,搞定马上揭帖!
SqlConnection cn = new SqlConnection(this.sqlstring);
//int pub_id=2003;
SqlCommand cmd = new SqlCommand("INSERT INTO images (images_id, logo) VALUES (2003,@BLOBData)", cn);
String strBLOBFilePath = @"C:/picture/bt1.jpg";//Modify this path as needed. //Read jpg into file stream, and from there into Byte array.
FileStream fsBLOBFile = new FileStream(strBLOBFilePath,FileMode.Open, FileAccess.Read);
Byte[] bytBLOBData = new Byte[fsBLOBFile.Length];
fsBLOBFile.Read(bytBLOBData, 0, bytBLOBData.Length);
fsBLOBFile.Close(); //Create parameter for insert command and add to SqlCommand object.
SqlParameter prm = new SqlParameter("@BLOBData", SqlDbType.VarBinary, bytBLOBData.Length, ParameterDirection.Input, false,
0, 0, null, DataRowVersion.Current, bytBLOBData);
cmd.Parameters.Add(prm); //Open connection, execute query, and close connection.
cn.Open();
cmd.ExecuteNonQuery();
cn.Close();
谢谢你们的连接,我会看的。
to乡村酒吧:
Sqlserver2000
to神农无忌:
谢谢你的代码。我现在试一试。
感谢各位关心,搞定马上揭帖!
http://www.aspx.cn/article/go.asp?id=267&typeid=2
http://www.c-sharpcorner.com/Code/2002/Feb/FlashCardsMG.asp
可以参考下
<IMG alt="" hspace=0 src="file:///C:/2.gif" align=baseline border=0>
drtreyre5yreytertyry
<IMG alt="" hspace=0 src="file:///C:/w.gif" align=baseline border=0>
sdigoiodstgui
<IMG alt="" hspace=0 src="file:///C:/w.gif" align=baseline border=0>
dksgjkldgj将以上文件存到数据库,再浏览
我是想将图片和文字分别存储。
不管你有没有存入数据库,或者存入的完不完整,它都是显示为<Binary>。
检查办法:看此字段大小(长短)。
因忙,不常来:[email protected]