从用户插入数据库 [英] insert into database from the user
问题描述
我有问题
我尝试插入数据库中,但是这种情况不会发生,我检查数据库以查看值,但什么都看不到!
我不知道为什么?
你能帮我吗
我想使用C#和Asp.net创建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.net;
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.net.您需要在按钮事件中添加一些代码.理想情况下,您应该将其分开并在不同的类中进行操作,以便将视图与模型和数据访问分开.
您可以使用的示例代码是.
You need to use ADO.net. 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?
这篇关于从用户插入数据库的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!