C#与SQL存储过程 [英] C# with SQL Stored Procedures

查看:68
本文介绍了C#与SQL存储过程的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我的任务是:将数据加载到

含义:不使用数据集或表适配器

注意:我的存储过程从特定表中选择所有记录.

想知道:如何通过C#将其连接

任何帮助将不胜感激!在此先感谢

My task is to: Load data into a Form using Stored Procedures only. 
 
Mean that: By not using Dataset or Table Adapters
 
Note: My Stored Procedure selects all records from a particular table.
 
Would like to know: How to connect this through my C# code and load datas into my form. 
 
Any help would be appreciated a lot!! Thanks in advance

推荐答案

典型的方式以 SqlCommand 类: http://msdn.microsoft.com/zh-CN/library/system.data.sqlclient.sqlcommand.aspx .您必须具有有效的连接字符串".

The typical way is shown as an example for SqlCommand class: http://msdn.microsoft.com/en-US/library/system.data.sqlclient.sqlcommand.aspx. You have to have a valid "connection string".

创建 SqlCommand 时,使用 CommandText 指定存储过程的名称.的价值 CommandType 将为 CommandType.StoredProcedure .

When you create the SqlCommand, use CommandText to specify the name of the stored procedure. The value of CommandType will be CommandType.StoredProcedure.

"while(reader.Read())" 循环中,使用各种 "reader.GetXXX" 函数来获取数据.

Inside the ‘while(reader.Read())’ loop, use various ‘reader.GetXXX’ functions to get the data.

您正在使用MSSQL数据库吗?

Are you working with MSSQL database?


这篇关于C#与SQL存储过程的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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