byte[] imagebytes = null;
SqlConnection con = new SqlConnection("Integrated Security=SSPI;Persist Security Info=False;Initial Catalog=Studen;Data Source=.");
con.Open();
SqlCommand com = new SqlCommand("select top 1(excel) from Excel1", con);
SqlDataReader dr = com.ExecuteReader();
while (dr.Read())
{
imagebytes = (byte[])dr.GetValue(0);
}
dr.Close();
com.Clone();
string content;
content = System.Text.Encoding.Default.GetString(imagebytes);
StreamWriter sr;
if (File.Exists("F://123.xls")) //如果文件存在,则创建File.AppendText对象
{
//sr = File.AppendText(FILE_NAME);
}
else //如果文件不存在,则创建File.CreateText对象
{
sr = File.CreateText("F://123.xls");
sr.WriteLine(content);
sr.Close();
}
SqlConnection con = new SqlConnection("Integrated Security=SSPI;Persist Security Info=False;Initial Catalog=Studen;Data Source=.");
con.Open();
SqlCommand com = new SqlCommand("select top 1(excel) from Excel1", con);
SqlDataReader dr = com.ExecuteReader();
while (dr.Read())
{
imagebytes = (byte[])dr.GetValue(0);
}
dr.Close();
com.Clone();
string content;
content = System.Text.Encoding.Default.GetString(imagebytes);
StreamWriter sr;
if (File.Exists("F://123.xls")) //如果文件存在,则创建File.AppendText对象
{
//sr = File.AppendText(FILE_NAME);
}
else //如果文件不存在,则创建File.CreateText对象
{
sr = File.CreateText("F://123.xls");
sr.WriteLine(content);
sr.Close();
}
解决方案 »
- C#用linq to xml如何向现有文件中附加节点
- 关于ArrayOfString
- 收藏 不显示删除回复显示所有回复显示星级回复显示得分回复 奇怪的问题,新增的类文件不编译,应该在哪里设置呢??
- C# winform combobox 动态添加 item,item要有value与text两个属性
- 怎样让执行拖放的时候窗体不会出现"假死"?
- 用c#开发的网站平台,sql数据库,系统用win 2003,100万人同时在线需要多少台服务器?每天100万的独立ip访问量又需要多少台服务器大概?
- 快捷方式
- 群号:1789924 [杭州IT人]
- C# wpf 代码文件夹路径怎么获取——
- 如何作出动态的下拉框效果.就像(studio.net)中的联想功能一样
- 请问有没有快速高效的合并byte[]的方法?
- MSchart 时间轴
不知道你克隆这个对象干什么的。
con.Open();打开的 我读出来的是一个System.Byte[]
第二,在拿数组,去写入文件。先保证第一步没有错con.Close();
数组已经读出来了,在imagebytes 里面 保存到excel文件,打开excel时候就能看到“System.Byte[]”
com.Close()是关闭
com.Clone();
string content;
改
dr.Close();
com.Close();
con.Close();
我个人感觉跟这个没什么关系
string content;
content = System.Text.Encoding.Default.GetString(imagebytes);
应该和这条语句有关吧 我要保存成excel文件
sw.WriteLine("写汉字,看看能不能写出来");
sw.Flush();
sw.Close();
content = System.Text.Encoding.Default.GetString(imagebytes);
content读出来之后就是“System.Byte[]”
这个将所有的都写在一起,你可以写到txt文件中,看看效果
既然要保存到文本 直接string[]不就得了