string strPath =
this
.FileUpload1.PostedFile.FileName.ToString ();
FileStream fs =
new
System.IO.FileStream(strPath, FileMode.Open, FileAccess.Read);
BinaryReader br =
new
BinaryReader(fs);
byte[] photo = br.ReadBytes((int)fs.Length);
br.Close();
fs.Close();
SqlConnection myConn =
new
SqlConnection(
"Data Source=.;Initial Catalog=stumanage;User ID=sa;Password=123"
);
string strComm =
" INSERT INTO stuInfo(stuid,stuimage) VALUES(107,@photoBinary )"
;
SqlCommand myComm =
new
SqlCommand(strComm, myConn);
myComm.Parameters.Add(
"@photoBinary"
, SqlDbType.Binary, photo.Length);
myComm.Parameters[
"@photoBinary"
].Value = photo;
myConn.Open();
if
(myComm.ExecuteNonQuery() > 0)
{
this
.Label1.Text =
"ok"
;
}
myConn.Close();