如何使用存储过程从.cs文件更新记录到asp.net [英] how to update record using stored procedure from .cs file to asp.net
本文介绍了如何使用存储过程从.cs文件更新记录到asp.net的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
你好,
i希望调用存储过程函数.cs到asp.net来更新记录
你可以引导或任何片段
使用(SqlConnection conn = new SqlConnection(Data
Source = localhost; Database = Northwind; Integrated Security = SSPI))
{$} b $ b SqlCommand命令= new SqlCommand(spName,conn);
command.CommandType = CommandType.StoredProcedure;
conn.Open();
SqlDataReader reader = command.ExecuteReader();
while(reader.Read())
{
Console.WriteLine(reader [ProductName]);
}
}
Source = localhost; Database = Northwind; Integrated Security = SSPI))
{$} b $ b SqlCommand命令= new SqlCommand(spName,conn);
command.CommandType = CommandType.StoredProcedure;
conn.Open();
SqlDataReader reader = command.ExecuteReader();
while(reader.Read())
{
Console.WriteLine(reader [ProductName]);
}
}
如果你想传递输入参数你可以通过
command.Parameters.Add( @ inputPar ,SqlDbType.Int).Value = 1 ;
SqlDbType是枚举你可以选择理想的数据类型作为输入参数及其值传递。
嗨suhelsa ...,
通过这个
http://www.asp.net/web-forms/tutorials/data-access/advanced-data-access-scenarios/creating-存储过程和用户定义的函数与托管代码cs [ ^ ]
http://idealprogrammer.com/net-languages/code-samples/sql-command-update-statement-source-code/ [ ^ 一>
hello,
i want to call stored procedure function .cs to asp.net to update records
can u guide or any snippets
解决方案
using(SqlConnection conn = new SqlConnection("Data Source=localhost;Database=Northwind;Integrated Security=SSPI")) { SqlCommand command = new SqlCommand("spName", conn); command.CommandType = CommandType.StoredProcedure; conn.Open(); SqlDataReader reader = command.ExecuteReader(); while (reader.Read()) { Console.WriteLine(reader["ProductName"]); } }
If you want to pass input parameters you can pass
command.Parameters.Add("@inputPar", SqlDbType.Int).Value = 1;
SqlDbType is enum you can choose desirable data type to pass as input parameter and its value.
Hi suhelsa...,
Go through this
http://www.asp.net/web-forms/tutorials/data-access/advanced-data-access-scenarios/creating-stored-procedures-and-user-defined-functions-with-managed-code-cs[^]
http://idealprogrammer.com/net-languages/code-samples/sql-command-update-statement-source-code/[^]
这篇关于如何使用存储过程从.cs文件更新记录到asp.net的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文