将数据插入ASP.NET中的SQL Server时出错

编程入门 行业动态 更新时间:2024-10-26 16:22:09
本文介绍了将数据插入ASP.NET中的SQL Server时出错的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

当我尝试将记录插入数据库时​​,我在asp中遇到问题 我得到这个错误

Hi i have problem in asp when i try to insert record to my db and i get this error

An explicit value for the identity column in table 'wiki' can only be specified when a column list is used and IDENTITY_INSERT is ON.

我正在寻找解决方案,但我得到了必须写以下内容的信息,但我不知道该在哪里写,或者它是否是正确的解决方法 SET IDENTITY_INSERT Wiki OFF如何在asp中编写它 这是我的代码:

and i have search for solution and i get that i must write the follwing,and i don''t know where to write it or if it''s a right solution SET IDENTITY_INSERT wiki OFF how to write it in asp here is my code:

string qry; //String file_id=TextBox1.Text; String file_name = TextBox2.Text; String file_size = TextBox3.Text; String file_url = TextBox4.Text; String file_category = TextBox5.Text; String file_view = TextBox6.Text; // String emp_id = TextBox7.Text; SqlConnection con = new SqlConnection(@"Data Source=SNIPERGHOST-PC\SQLEXPRESS;Initial Catalog=PM;Integrated Security=True;Pooling=False"); con.Open(); SqlCommand cmd; SqlDataSource sds = new SqlDataSource(); qry = "insert into wiki values('" + file_name + "','" + file_size + "','" + file_url + "','" + file_category + "','" + file_view +"','"+ "')"; cmd = new SqlCommand(qry, con); cmd.ExecuteNonQuery(); con.Close(); //Image1.Visible = true; string ToRedirectURL = "viewfiles.aspx"; Response.AppendHeader("REFRESH", "5;URL=" + ToRedirectURL); // Response.Redirect("comment.aspx",true);

推荐答案

首先,您应该使用存储过程来执行此操作. 这是一个解决方案: Firstly you should be using a stored procedure to do this. Here''s a solution: qry = "insert into wiki (column1, column2, column3, column4) values('" + file_name + "','" + file_size + "','" + file_url + "','" + file_category + "','" + file_view +"','"+ "')";

您需要指定数据将进入的列.将列重命名为您实际将数据放入的列.

You need to specify the columns into which the data is going to go. Rename the columns to those that you are actually putting the data into.

更多推荐

将数据插入ASP.NET中的SQL Server时出错

本文发布于:2023-10-12 17:35:05,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1485399.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:数据   ASP   NET   SQL   Server

发布评论

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

>www.elefans.com

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