使用存储过程加载数据 [英] Load data using Stored Procedures

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

问题描述

您好,



我的任务是:仅使用存储过程将数据加载到表单中。



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



注意:我的存储过程选择所有记录来自特定的表。



想知道:如何通过我的C#代码连接它并将数据加载到我的表单中。



任何帮助都会受到很多赞赏!在此先感谢

Hello,

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

推荐答案

SqlConnection conn = new SqlConnection(Connectionstring ....);

SqlCommand cmd = new SqlCommand() ;

cmd.Connection = conn;

cmd.CommandText =Procedurename .....;

cmd.CommandType = CommandType。 StoredProcedure;

cmd.Parameters.Add(new SqlParameter(Parametr Name,Parameter value));

cmd.Connection.Open();

SqlDataReader dr = cmd.ExecuteReader(CommandBehavior.CloseConnection);

DataTable dt = new DataTable();

dt.Load(dr);

dataGridView1.DataSource = dt;





如果您有任何疑问,请告诉我
SqlConnection conn = new SqlConnection("Connectionstring....");
SqlCommand cmd = new SqlCommand();
cmd.Connection = conn;
cmd.CommandText = "Procedurename..... ";
cmd.CommandType = CommandType.StoredProcedure;
cmd.Parameters.Add(new SqlParameter("Parametr Name", "Parameter value"));
cmd.Connection.Open();
SqlDataReader dr = cmd.ExecuteReader(CommandBehavior.CloseConnection);
DataTable dt = new DataTable();
dt.Load(dr);
dataGridView1.DataSource = dt;


Please let me know if you have any doubt in


这篇关于使用存储过程加载数据的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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