文件上传错误,“在所选数据源”上找不到”
本文关键字:数据源 找不到 错误 文件 | 更新日期: 2023-09-27 18:04:38
我编写了以下代码,当它只是将文件上传到文件夹时,一切都很好。我已经改变了它插入文件名和文件路径到数据库,我得到一个错误:
在选定的数据源上找不到名称为'DataUpload'的字段或属性
DataUpload是文件夹名称,以前工作正常。我可能错过了一些简单的东西,但我没有看到它。
protected void ButtonSubmit_Click(object sender, EventArgs e)
{
try
{
FileUpload1.SaveAs(Server.MapPath("DataUpload''" + FileUpload1.FileName));
Guid newGUID = Guid.NewGuid();
SqlConnection conn = new SqlConnection(ConfigurationManager.ConnectionStrings["ConnectionString"].ConnectionString);
conn.Open();
string FileName = Path.GetFileName(FileUpload1.PostedFile.FileName);
string InsertUser = "INSERT INTO UserUpload (ID, Comment, FilePath, FileName) VALUES (@ID, @Comment, @FilePath, @FileName)";
SqlCommand com = new SqlCommand(InsertUser, conn);
com.Parameters.AddWithValue("@ID", newGUID.ToString());
com.Parameters.AddWithValue("@Comment", TextBoxComment.Text);
com.Parameters.AddWithValue("@FilePath", "DataUpload/" + FileName);
com.Parameters.AddWithValue("@FileName", FileName);
com.ExecuteNonQuery();
LabelMessage.Text = ("Your Upload Is Complete");
conn.Close();
}
catch (Exception ex)
{
LabelMessage.Text = ("Error:" + ex.Message);
}
}
为FilePath创建的字符串添加单引号,如:string.Format("'DataUpload/{0}'", FileName);