尝试/ Catch方法错误ASP.NET(Try/Catch method error ASP.NET)

编程入门 行业动态 更新时间:2024-10-25 17:26:35
尝试/ Catch方法错误ASP.NET(Try/Catch method error ASP.NET)

我正在努力完成这项工作。 我希望它检查插入后是否存在记录,但它总是返回一个错误:第1行:'nvarchar'附近的语法不正确。 有人能指出我的声明有什么不对吗? 此外,如果你有更好的尝试捕捉方法,请更多地启发我。 刚刚在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"; }

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

I'm trying to make this work. I want it to check if a record exist after inserting but it always return an error: Line 1: Incorrect syntax near 'nvarchar'. Can someone point out to me whats wrong in my declaration? Also if you have a better try catch method please enlighten me more. Just new to programming in ASP.NET

Thanks in advance.

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"; }

EDIT: There just removed the datatypes.

最满意答案

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

尝试

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)";

You don't have to include data type in insert statements. Skip them.

Try

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)";

更多推荐

本文发布于:2023-08-01 03:48:00,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1354022.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:错误   方法   Catch   ASP   error

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!