private void upload_Click(object sender, System.EventArgs e)
{
if(File.PostedFile!=null && File.PostedFile.ContentLength!=0)
{
string filename = File.PostedFile.FileName.Substring(File.PostedFile.FileName.LastIndexOf("\\")+1);   //文件名称
string filetype = File.PostedFile.ContentType;  //文件类型
int filesize = File.PostedFile.ContentLength;  //文件大小
byte[] filedata = new byte[filesize];      //文件内容
File.PostedFile.InputStream.Read(filedata,0,filesize);
string con = ConfigurationSettings.AppSettings["SqlConnectionString"];
SqlConnection conn = new SqlConnection(con);
SqlCommand cmd = conn.CreateCommand();
cmd.CommandText = "INSERT INTO file(文件名称,文件类型,文件大小,文件内容) VALUES ('" + filename + "', '" + filetype + "', '" + filesize + "', @filedata)";
cmd.Parameters.Add("@filedata",SqlDbType.Binary,50).Value = filedata;
conn.Open();

try
{
cmd.ExecuteNonQuery();
}
catch(Exception ex)
{
Console.WriteLine("Exception in main:" + ex.Message);
}
finally
{
cmd.Dispose();
}
conn.Close();
//上传成功
}
else
{
Response.Write("请选择文件");
} }