如何在ASP.NET中调用SQL Server存储过程 [英] How to call SQL Server stored procedures in ASP.NET

查看:97
本文介绍了如何在ASP.NET中调用SQL Server存储过程的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如何在ASP.pls中调用SQL Server存储过程为我提供了Ap.net + C#中的代码.

How to call SQL Server stored procedures in ASP.pls provide me code in Ap.net + C#

推荐答案

没有任何形式的ASP.NET代码数据访问. ASP.NET不会这样做. C#当然可以.你为什么要问这样的问题?我们提供给您的任何代码都无法复制和粘贴,我们没有您的数据库连接字符串或架构.而且,既然您显然是一个绝对的初学者,那么与论坛回复相比,一篇文章是一种更好的学习方法.我将花一分钟的时间写信给像你这样的人.我会花数小时写一篇文章来填写所有细节,并确保它清楚.
There is no ASP.NET code for any sort of data access. ASP.NET does not do that. C# does, of course. Why would you ask such a question ? Any code we give you cannot be copied and pasted, we don''t have your database connection string, or schema. And, given that you plainly are an absolute beginner, an article is a far better way to learn than a forum reply. I''ll spend a minute writing a reply to someone like you. I''d spend hours writing an article to fill in all the details and make sure it was clear.


在Internet上进行搜索.您会发现大量可以帮助您的链接.
对于初学者,请参见此处 [
Do a search on the internet. You will find tons of links that can help you out.
For starters, see here[^].


,您可以尝试一下. .
you can try this..
try
  {
     sqlConnection = new SqlConnection(dbConnectionString);
     SqlCommand command = new SqlCommand("sp_Insert", sqlConnection);
     command.CommandType = CommandType.StoredProcedure;
     command.Parameters.Add("@Name", SqlDbType.VarChar).Value = Name.Text;
     command.Parameters.Add("@Father Name", SqlDbType.VarChar).Value = FatherName.Text;
     command.Parameters.Add("@Email", SqlDbType.VarChar).Value = Email.Text;
     command.Parameters.Add("@Land Line No", SqlDbType.VarChar).Value = LandLineNo.Text;
     command.Parameters.Add("@Mobile No", SqlDbType.VarChar).Value = Mobile.Text;
     command.Parameters.Add("@Country", SqlDbType.VarChar).Value = Country.Text;
     command.Parameters.Add("@Gender", SqlDbType.VarChar).Value = Gender.Text;
     sqlConnection.Open();
     return command.ExecuteNonQuery();
     sqlConnection.Close();
  }
catch (SqlException ex)
  {
     Console.WriteLine("SQL Error" + ex.Message.ToString());
     return 0;
  }



第二行"sp_Insert"是存储过程名称,您只需替换存储过程名称
第四行"@Name"是存储过程参数名称,您只需添加带有控制值的参数名称
例如
command.Parameters.Add(< @ your_parameter>",SqlDbType.< db attribute =">).Value =< your control =" name =">

如果有任何问题,请尝试让我知道.

谢谢



in second line "sp_Insert" is store procedure name you just replace your store procedure name
in fourth line "@Name" is store procedure parameter name you just add your parameter name with control value
for example
command.Parameters.Add("<@your_parameter>",SqlDbType.<db attributes="">).Value=<your control="" name="">

try this if any problem let me know.

Thanks


这篇关于如何在ASP.NET中调用SQL Server存储过程的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆