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

问题描述

大家好,
在C#WinApp中,我将调用存储过程并在listView中显示结果.我使用datareader.

非常感谢...

Hello everybody,
in a C# WinApp I would to call a stored procedure and to display a results in a listView.I use datareader.

Thanks so much...

推荐答案

SqlCommand command = new SqlCommand();
        connection.Open();
command.Connection = connection;
command.CommandType=CommandType.StoredProcedure;
command.CommandText = "SPName";
        SqlDataReader reader = command.ExecuteReader();

        if (reader.HasRows)
        {
            while (reader.Read())
            {
                Console.WriteLine("{0}\t{1}", reader.GetInt32(0),
                    reader.GetString(1));
            }
        }
        else
        {
            Console.WriteLine("No rows found.");
        }
        reader.Close();


SqlCommand cmd=new SqlCommand("spMyProc", con);
cmd.CommandType=CommandType.StoredProcedure;
SqlDataReader sdr=new SqlDataReader();
sdr=cmd.ExecuteReader();
while(sdr.read()){
    //Your code goes here.
}
sdr.Dispose();
cmd.Dispose();
con.Close();



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

07-11 20:14