【发布时间】:2021-02-01 06:02:25
【问题描述】:
protected void Upload(object sender, EventArgs e)
{
//Extract Image File Name.
string fileName = Path.GetFileName(FileUpload1.PostedFile.FileName);
//Set the Image File Path.
string filePath = "~/Uploads/" + fileName;
//Save the Image File in Folder.
FileUpload1.PostedFile.SaveAs(Server.MapPath(filePath));
string mycon = "server =localhost; Uid=root; password = ; persistsecurityinfo = True; database =ovs; SslMode = none";
MySqlConnection con1 = new MySqlConnection(mycon);
// string sql = "INSERT INTO candidate VALUES(@Name, @Path)";
MySqlCommand cmd = null;
cmd = new MySqlCommand("INSERT INTO candidate(candidateImage,path where studentID ='" + Session["UserName"] + "') VALUES (@Name,@Path)", con1);
cmd.Parameters.AddWithValue("@Name", fileName);
cmd.Parameters.AddWithValue("@Path", filePath);
con1.Open();
cmd.ExecuteNonQuery();
con1.Close();
}
当用户点击上传按钮时,图片和路径将被保存到属于特定用户的数据库中。比如ID为R1001的用户登录自己的账号,点击上传按钮,图片和路径就会保存在数据库中的R1001下。我显示错误消息,提示存在语法错误,但我无法找到它
【问题讨论】:
-
你的错误信息是什么?
-
它说 cmd = new MySqlCommand("INSERT INTO Candidate(candidateImage,path where studentID ='" + Session["UserName"] + "') VALUES (@Name, @Path)", con1);
-
为什么你在 (candidateImage,path where studentID ='" + Session["UserName"] + "') 插入时间在哪里?
-
StudentID Name Path R1001 当前数据库是这样的,我的意图是当用户点击上传按钮时,名称和路径将被添加。 StudentID 名称 路径 R1001 image1 uploads/ images1
-
分享你的表格架构。我的意思是表格的字段,以便知道哪些字段是必需的