如何在使用C#和Sql Server 2005的ASP.net中使用存储过程 [英] How to use Stored Procedure in ASP.net using C# with Sql Server 2005
本文介绍了如何在使用C#和Sql Server 2005的ASP.net中使用存储过程的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
亲爱的所有人,
我想在我的基于网络的应用程序中使用存储过程。它是在Visual Studio 2005上开发并使用数据库Sql Server 2005.
请同时提供C#代码以便于理解。
提供对于所有操作如创建过程,插入,更新,删除和选择结果(选择查询)
Dear All,
I want to use stored procedure in my web based application. It is develop on Visual Studio 2005 and using database Sql Server 2005.
Please also provide C# code to easy understanding.
It is provide for all operation as Create procedure, insertion, Updateion, Deletion and Select result(select query)
推荐答案
试试这个
如何调用存储过程asp.net c#code [ ^ ]
http://www.c-sharpcorner.com/UploadFile/gtomar/storedprocedure12052007003126AM/storedprocedure.aspx [ ^ ]
try this
how to call stored procedure in asp.net c# code[^]
http://www.c-sharpcorner.com/UploadFile/gtomar/storedprocedure12052007003126AM/storedprocedure.aspx[^]
看看这里:
如何创建带参数的SQL Server存储过程 [ ^ ]
使用存储过程和命令 [ ^ ]
如何:使用EntityCommand执行参数化存储过程 [ ^ ]
http://support.microsoft.com/kb/310070 [ ^ ]
启动是否足够?
Have a look here:
How to create a SQL Server stored procedure with parameters[^]
Using Stored Procedures with a Command[^]
How to: Execute a Parameterized Stored Procedure Using EntityCommand[^]
http://support.microsoft.com/kb/310070[^]
Is it enough for start?
>
你可以试试这样的东西
Hi,
you can try some thing like this
create procedure insert_data
(
@Id int, @Name Varchar(20) , @address varchar(50)
)
begin
Insert into table1(Id,Name,address) values(@Id,@Name,@address)
end
您可以使用以下c#代码点击按钮来插入数据
you can use the following c# code on button click to insert data
try
{
sqlConnection con = new SqlConnection(dbConnectionString);
SqlCommand comm= new SqlCommand("insert_data", con);
comm.CommandType = CommandType.StoredProcedure;
comm.Parameters.Add("@Id", SqlDbType.VarChar).Value = txtId.Text;
comm.Parameters.Add("@Name", SqlDbType.DateTime).Value = txtName.Text;
comm.Parameters.Add("@Address", SqlDbType.DateTime).Value = txtaddress.Text;
sqlConnection.Open();
return comm.ExecuteNonQuery();
sqlConnection.Close();
}
catch (SqlException ex)
{
Console.WriteLine("SQL Error" + ex.Message.ToString());
return 0;
}
我希望它能帮到你..
I hope it will help you..
这篇关于如何在使用C#和Sql Server 2005的ASP.net中使用存储过程的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文