I am working on a database application in C#. I had a requirement to display data on a table and I am now done with that. But my business logic is hardcoded to my code. Now I want to go ahead and use Stored procedures with my code. What are the modifications that I need to do. A simple list of steps would be enough 🙂
SqlConnection myConnection = new SqlConnection("user id=dbblabla;" +
"password=1234;server=localhost\\SQLEXPRESS;" +
"Trusted_Connection=yes;" +
"database=myDB; " +
"connection timeout=30");
try
{
myConnection.Open();
} catch (SqlException excep){
Console.WriteLine(excep.StackTrace);
}
String selectionQuery = "SELECT * FROM myTable";
SqlDataAdapter myAdapter = new SqlDataAdapter(selectionQuery,myConnection);
DataSet ds = new DataSet();
myAdapter.Fill(ds,"AllInfo");
dataGridSearchOutput.DataSource = ds.Tables["AllInfo"].DefaultView;
I started from creating a new SQL command but I am not sure I am using the correct way.
SqlCommand newCommand = new SqlCommand("SELECT * FROM PMInfo");
newCommand.CommandType = CommandType.StoredProcedure;
Stored-Procedure
C# code