gpt4 book ai didi

c# - Try/Catch 方法错误 ASP.NET

转载 作者:行者123 更新时间:2023-11-30 13:28:22 26 4
gpt4 key购买 nike

我正在努力使这项工作。我希望它在插入后检查记录是否存在,但它总是返回错误:第 1 行:'nvarchar' 附近的语法不正确。有人可以指出我的声明有什么问题吗?另外,如果您有更好的try catch方法,请多多赐教。刚刚接触 ASP.NET 编程

提前致谢。

protected void Page_Load(object sender, EventArgs e)
{
string connString_LibrarySystem = "Server=DEVSERVER;User ID=sa;Password=Sup3r-Us3r;Database=LibrarySystem";
string strSQL = "INSERT INTO TblBooks (bookid, booktitle, lastname, firstname, description, categoryid, dateadded, statusid, quantity, isdeleted) VALUES (@bookid, @booktitle, @lastname, @firstname, @description, @categoryid, @dateadded, @statusid, @quantity, @isdeleted)";

SqlConnection conn = new SqlConnection(connString_LibrarySystem);

conn.Open();

SqlCommand cmd = new SqlCommand();

cmd = new SqlCommand(strSQL, conn);
cmd.Parameters.AddWithValue("@bookid", Request.Form["bookid"]);
cmd.Parameters.AddWithValue("@booktitle", Request.Form["booktitle"]);
cmd.Parameters.AddWithValue("@lastname", Request.Form["lastname"]);
cmd.Parameters.AddWithValue("@firstname", Request.Form["firstname"]);
cmd.Parameters.AddWithValue("@description", Request.Form["description"]);
cmd.Parameters.AddWithValue("@categoryid", Request.Form["categoryid"]);
cmd.Parameters.AddWithValue("@dateadded", Request.Form["dateadded"]);
cmd.Parameters.AddWithValue("@statusid", Request.Form["statusid"]);
cmd.Parameters.AddWithValue("@quantity", Request.Form["quantity"]);
cmd.Parameters.AddWithValue("@isdeleted", Request.Form["isdeleted"]);

cmd.ExecuteNonQuery();
{
conn.Close();
}
statuslabel.Text = "Insert successful";
}

编辑:刚刚删除了数据类型。

最佳答案

您不必在插入语句中包含数据类型。跳过它们。

尝试

string strSQL = "INSERT INTO TblBooks (bookid, booktitle, lastname, firstname, description, categoryid, dateadded, statusid, quantity, isdeleted) VALUES (@bookid, @booktitle , @lastname, @firstname, @description, @categoryid, @dateadded , @statusid , @quantity, @isdeleted)";

关于c# - Try/Catch 方法错误 ASP.NET,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/6053340/

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