要从存储过程填充数据集,您将具有如下代码:
SqlConnection mySqlConnection =new SqlConnection("server=(local);database=MyDatabase;Integrated Security=SSPI;"); SqlCommand mySqlCommand = mySqlConnection.CreateCommand(); mySqlCommand.CommandText = "IDCategory"; mySqlCommand.CommandType = CommandType.StoredProcedure; mySqlCommand.Parameters.Add("@IDCategory", SqlDbType.Int).Value = 5; SqlDataAdapter mySqlDataAdapter = new SqlDataAdapter(); mySqlDataAdapter.SelectCommand = mySqlCommand; DataSet myDataSet = new DataSet(); mySqlConnection.Open(); mySqlDataAdapter.Fill(myDataSet);您的连接字符串将有所不同,并且有几种不同的方法可以执行此操作,但这应该可以帮助您....一旦掌握了其中的一些内容,请查看Using语句。它有助于清理资源,并且需要更少的代码行。假定存储过程名称IDCategory具有一个称为相同参数的参数。您的设置可能有所不同。
在这种情况下,您的存储过程将类似于:
CREATE PROC [dbo].[IDCategory] @IDCategory intAS SELECT IDListing, IDCategory, Price, Seller, Image FROM whateveryourtableisnamed WHERe IDCategory = @IDCategory
这是有关存储过程基础的链接:http : //www.sql-
server-
performance.com/articles/dba/stored_procedures_basics_p1.aspx
这是有关ADO.Net的数据集和其他项目的链接:http
:
//authors.aspalliance.com/quickstart/howto/doc/adoplus/adoplusoverview.aspx



