SqlConnection conn = new SqlConnection("Data
Source=servername;Database=databasenam... Security=SSPI");
SqlCommand command = new SqlCommand("NameOfStoredProcedure", conn);
command.CommandType = CommandType.StoredProcedure;
command.Parameters.Add("@Param1", SqlDbType.Int).Value = 10; // or any value, assuming it's an int
SqlDataAdapter adapter = new SqlDataAdapter(command);
DataSet ds = new DataSet();
adapter.Fill(ds, "Table");
Datagrid1.DataSource = ds;
Datagrid1.DataMember = "Table";
But of course, i'd rather use de Data Access Application Block which encapsulates all database access in one single static class (SQLHelper).
(you can download this from
http://msdn.microsoft.com/library/defaul...
)
How do I call a stored procedure with parameters in C# using Ado.net?
Clarton seems to know what he's talking about.
Subscribe to:
Post Comments (Atom)
No comments:
Post a Comment