从用户插入数据库

编程入门 行业动态 更新时间:2024-10-28 21:19:56
本文介绍了从用户插入数据库的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

我有问题 我尝试插入数据库中,但是这种情况不会发生,我检查数据库以查看值,但什么都看不到! 我不知道为什么? 你能帮我吗 我想使用C#和Asp创建Web应用程序; 1-首先,我在数据库中有Table3,其中Table3具有2列[Emp_id]& [password] 对于[Emp_id]的数据类型为nchar(5),对于[password]的数据类型为nchar(10) 然后我创建存储过程,如下所示:

Hi, i have a problem i try to insert into database but this not happen i check my database to see value but i see nothing !! i don''t know WHY ?? can you help me i want to create web application use C# and Asp; 1- first i have Table3 in Database which have 2 column [Emp_id]&[password] with data type nchar(5) for [Emp_id], and nchar(10) for [password] then i create Stored procedure as following:

ALTER PROCEDURE dbo.StoredProcedure1 @Emp_id nchar(5), @Password nchar(10) AS INSERT INTO Table3 (Emp_id,password) VALUES (@Emp_id,@Password) RETURN

2在我的"aspx"页面中,我拖动2个文本框和1个按钮,然后在"aspx.cs"页面中,在按钮期间,我尝试将插入代码写入数据库,并使用存储过程"来做到这一点.请注意,来自用户的插入 谢谢:)

2-in my "aspx" page i drag 2 textboxes and 1 button then in "aspx.cs" page and during the button i try to write insert code into database use "Stored procedure" how i do that. Note that, the insert from the user Thanks :)

推荐答案

您需要知道如何使用ADO.NET使用存储过程. 只需从此处 [ ^ ],前几个: 链接1 [ ^ ] 链接2 [ ^ ] 链接3 [ ^ ] You need to know how to use stored procedure using ADO.NET. Just pick any link from here[^], first few: Link 1[^] Link 2[^] Link 3[^]

您需要使用ADO.您需要在按钮事件中添加一些代码.理想情况下,您应该将其分开并在不同的类中进行操作,以便将视图与模型和数据访问分开. 您可以使用的示例代码是. You need to use ADO. You need to put some code into the event of the button. Ideally you should separate and do it in a different class so that you separate your view from your model and data access. Sample Code you can use is. SqlConnection sqlConnection; SqlCommand sqlCommand; SqlParameter sqlparameter; DataTable dt = null; try { sqlConnection = Database.DatabaseConnection; sqlCommand = new SqlCommand(); sqlCommand.Connection = sqlConnection; sqlCommand.CommandType = CommandType.StoredProcedure; sqlCommand.CommandTimeout = 0; sqlCommand.CommandText = "StoredProcedure1"; sqlparameter = new SqlParameter(); sqlparameter.ParameterName = "@Emp_id"; sqlparameter.SqlDbType = SqlDbType.VarChar; sqlparameter.Value = Emp_id; sqlparameter.Direction = ParameterDirection.Input; sqlCommand.Parameters.Add(sqlparameter); sqlparameter = new SqlParameter(); sqlparameter.ParameterName = "@Password"; sqlparameter.SqlDbType = SqlDbType.VarChar; sqlparameter.Value = Password; sqlparameter.Direction = ParameterDirection.Input; sqlCommand.Parameters.Add(sqlparameter); SqlDataAdapter sqlDA = new SqlDataAdapter(); dt = new DataTable(); sqlDA.SelectCommand = sqlCommand; sqlConnection.Open(); sqlDA.Fill(dt); sqlConnection.Close(); } catch (Exception ex) { } return dt;

非常感谢您的回答 请问一个小问题! 是否可以通过使用按钮将值插入数据库并保存在数据库中?还是不? Thank you so much for answer can i ask a small question, please ! it is possible to insert value into database by using button and save in database ? or not?

更多推荐

从用户插入数据库

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

发布评论

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

>www.elefans.com

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