Contest. The Open ();
String biaoti1=biaoti. Value;
. String caixi=Request Form (" type ");
String cidyuju=the string. Format (" select c_id from class where c_name='" + caixi + "' ");
SqlCommand sql0=new SqlCommand (cidyuju, contest);
The object cid=sql0. ExecuteScalar ();
Contest. The Close ();
If (fil1. HasFile)//determine whether selection file
{
String getfile=fil1. PostedFile. FileName;
String imgtype=fil1. PostedFile. ContentType;//file type
Int I=getfile. LastIndexOf (". ");
The string filename.
Filename=getfile. ToLower (). The Substring (I, getfile. Length - I);
if (! (filename==". JPG "| | filename==" jpeg "| | filename==". GIF "| | filename==" PNG "))
{
ClientScript. RegisterStartupScript (ClientScript. GetType (), "uploaderr", "& lt; Script language='javascript' defer> Alert (' upload file format is not correct) & lt;/script>" );
return;
}
//upload file
//FileUploadCompant (enclosing FileUpload1);
String strpath=fil1. PostedFile. FileName;//file name
Byte [] getimage=new byte [fil1. PostedFile. ContentLength];//will be the length of the image into a binary file upload ContentLength said
The Stream filestream=fil1. PostedFile. InputStream;
//read the data
Filestream. Read (getimage, 0, fil1. PostedFile. ContentLength);
Contest. The Open ();
If (Session (" username ")!=null)
{
//define
String eid=filename;
String uid=Session (" username "). The ToString ();
String zhengwen.=the Request Form (" zhengwen "),
String nianyueri=DateTime. Now. ToString (" yyyy - MM - dd ");
//SqlConnection contest=new SqlConnection (" server=. The database=foodblog; Uid=sa; The PWD=fuyiyun0506 ");
SqlCommand command=new SqlCommand (" INSERT INTO essay (e_id c_id, user_id, e_name, e_content, e_time, imgtype, imgdata, impath) VALUES (@ e_id @ c_id, @ user_id, @ e_name, @ e_content, @ e_time, @ imgtype, @ imgdata, @ impath) ", contest);
//parameters into database
SqlParameter pare1=new SqlParameter (" @ e_id ", SqlDbType NChar, 10);
Pare1. Value=https://bbs.csdn.net/topics/eid;
Command. The Parameters. The Add (pare1);
SqlParameter pare2=new SqlParameter (" @ c_id ", SqlDbType NChar, 10);
Pare2. Value=https://bbs.csdn.net/topics/cid;
Command. The Parameters. The Add (pare2);
SqlParameter pare3=new SqlParameter (" @ user_id, "SqlDbType NChar, 10);
Pare3. Value=https://bbs.csdn.net/topics/uid;
Command. The Parameters. The Add (pare3);
SqlParameter pare4=new SqlParameter (" @ e_name ", SqlDbType NChar, 10);
Pare4. Value=https://bbs.csdn.net/topics/biaoti1;
Command. The Parameters. The Add (pare4);
SqlParameter pare5=new SqlParameter (" @ e_content ", SqlDbType. VarChar, 8000);
Pare5. Value=https://bbs.csdn.net/topics/zhengwen;
Command. The Parameters. The Add (pare5);
SqlParameter pare6=new SqlParameter (" @ e_time ", SqlDbType. Date);
Pare6. Value=https://bbs.csdn.net/topics/nianyueri;
Command. The Parameters. The Add (pare6);
SqlParameter paretype=new SqlParameter (" @ imgtype ", SqlDbType VarChar, 50);
Paretype. Value=https://bbs.csdn.net/topics/imgtype;
Command. The Parameters. The Add (paretype);
SqlParameter pareimgdata=https://bbs.csdn.net/topics/new SqlParameter (" @ imgdata ", SqlDbType. Image).
Pareimgdata. Value=https://bbs.csdn.net/topics/getimage;
Command. The Parameters. The Add (pareimgdata);
SqlParameter pareimgpath=new SqlParameter (" @ impath ", SqlDbType. VarChar, 200);
Pareimgpath. Value=https://bbs.csdn.net/topics/strpath;
Command. The Parameters. The Add (pareimgpath);
Int iresult=command. ExecuteNonQuery ();
If (iresult & gt; 0)
{
String strMsg="submit success!" ;
System. Web. HttpContext. Current. The Response. Write (" & lt; Script Language='JavaScript' & gt; Window. The alert (' + strMsg + ""); </script>" );
}
The else
{
String strMsg="submit failure!" ;
System. Web. HttpContext. Current. The Response. Write (" & lt; Script Language='JavaScript' & gt; Window. The alert (' + strMsg + ""); </script>" );
}
Contest. The Close ();
}
}
CodePudding user response:
Everybody to help