标题:图片在数据库中保存
只看楼主
zouzhou1984
Rank: 1
等 级:新手上路
帖 子:8
专家分:0
注 册:2007-11-13
得分:0 
SqlConnection mycon = new SqlConnection("conString")
SqlCommand mycmd = mycon.CreateCommand();
= CommandType.StoredProcedure;
= "StoredProcedureName";
SqlParameter para14 = new SqlParameter();
                para14.ParameterName = "@picimg";
                para14.SqlDbType = SqlDbType.Image;
                string filename = openFileDialog1.FileName;
                //从文件中读数据
                FileStream fs = new FileStream(filename, FileMode.Open, FileAccess.Read);
                //建立一个2进制数组
                byte[] mydata = new byte[fs.Length];
                fs.Read(mydata, 0, (int)fs.Length);
                fs.Close();
                para14.Value = mydata;
mycmd.Parameters.Add(para14);
mycmd.ExecuteNonQuery();

[[it] 本帖最后由 zouzhou1984 于 2008-4-13 22:43 编辑 [/it]]
2008-04-13 22:34



参与讨论请移步原网站贴子:https://bbs.bccn.net/thread-203561-1-1.html




关于我们 | 广告合作 | 编程中国 | 清除Cookies | TOP | 手机版

编程中国 版权所有,并保留所有权利。
Powered by Discuz, Processed in 0.367115 second(s), 7 queries.
Copyright©2004-2025, BCCN.NET, All Rights Reserved