gpt4 book ai didi

c# - '); 附近的语法不正确

转载 作者:行者123 更新时间:2023-11-29 02:27:11 25 4
gpt4 key购买 nike

我的代码有错误。

代码执行直接流向 catch block 并说:incorrect syntax near ');

我想在数据库中保存一个文件,然后再调用。

public partial class newsrv : System.Web.UI.Page{
string dir = "C://fileup//";

protected void Page_Load(object sender, EventArgs e){
if (!Directory.Exists(dir)){
Directory.CreateDirectory(dir);
}
}

protected void DropDownList1_SelectedIndexChanged(object sender, EventArgs e){

}

protected void Button1_Click(object sender, EventArgs e){
SqlConnection con = new SqlConnection("Data Source=.\\SQLEXPRESS;AttachDbFilename=|DataDirectory|DB.mdf;Integrated Security=True;User Instance=True");
string fname = FileUpload1.PostedFile.FileName;
try{
SqlCommand cmd = new SqlCommand("INSERT INTO OrderNum (SrviceType, Msg,[File]) VALUES ('" + DropDownList1.SelectedItem.Text + "','" + TextBox1.Text + "' ,'" + FileUpload1.PostedFile.FileName + "') );", con);
con.Open();

try {
int res = cmd.ExecuteNonQuery();
if (res > 0){
System.Windows.Forms.MessageBox.Show("success");
}
Label2.Text = TextBox1.Text;
FileUpload1.SaveAs(dir + fname);
Label1.Text = " file name uploaded succ ";
FileUpload1.Visible = true;
}catch (Exception ex){
System.Windows.Forms.MessageBox.Show(ex.Message);
}
}catch{
Label1.Text = " file name not uploaded ";
FileUpload1.Visible = false;
con.Close();
}finally{
con.Close();
}
}

protected void TextBox1_TextChanged(object sender, EventArgs e){

}
}

最佳答案

看起来你在 SQL 语句的末尾有一个额外的 );...

... + TextBox1.Text + "' ,'" + FileUpload1.PostedFile.FileName + "') );", con);

^^
remove these

关于c# - '); 附近的语法不正确,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/19470764/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com