62,242
社区成员




protected void Button1_Click(object sender, EventArgs e)
{
//写入
string path = this.FileUpload1.PostedFile.FileName;
FileStream stream = new FileStream(path, FileMode.Open, FileAccess.Read);
int length = this.FileUpload1.PostedFile.ContentLength;
byte[] wordData = new byte[length];
stream.Read(wordData, 0, length);
stream.Close();
SqlConnection con = new SqlConnection(connectionString);
con.Open();
SqlCommand cmd = new SqlCommand("insert into word values('test','" + wordData + "')", con);
cmd.ExecuteNonQuery();
con.Close();
}
protected void Button2_Click(object sender, EventArgs e)
{
//读取
SqlConnection con = new SqlConnection(connectionString);
con.Open();
SqlCommand cmd = new SqlCommand("select content from word where id=9", con);
SqlDataReader sdr = cmd.ExecuteReader();
FileStream fs;
BinaryWriter bw;
byte[] outbyte = null;
string filePath = @"D:\word.doc";
while (sdr.Read())
{
fs = new FileStream(filePath, FileMode.OpenOrCreate, FileAccess.Write);
bw = new BinaryWriter(fs);
outbyte=(byte[])sdr["content"];
bw.Write(outbyte, 0, outbyte.Length);
bw.Flush();
bw.Close();
fs.Close();
}
sdr.Close();
con.Close();
}