How to use a DataAdapter with stored procedure and parameter

I got it!…hehe protected DataTable RetrieveEmployeeSubInfo(string employeeNo) { SqlCommand cmd = new SqlCommand(); SqlDataAdapter da = new SqlDataAdapter(); DataTable dt = new DataTable(); try { cmd = new SqlCommand(“RETRIEVE_EMPLOYEE”, pl.ConnOpen()); cmd.Parameters.Add(new SqlParameter(“@EMPLOYEENO”, employeeNo)); cmd.CommandType = CommandType.StoredProcedure; da.SelectCommand = cmd; da.Fill(dt); dataGridView1.DataSource = dt; } catch (Exception x) { MessageBox.Show(x.GetBaseException().ToString(), “Error”, MessageBoxButtons.OK, MessageBoxIcon.Error); } finally { … Read more

Is datareader quicker than dataset when populating a datatable?

The DataAdapter uses a DataReader under the hood so your experience would likely be the same. The benefit of the DataAdapter is you cut out a lot of code that would need maintenance. This debate is a bit of a religious issue so definitely look around and decide what works best for your situation: http://blogs.msdn.com/memilavi/archive/2008/02/18/datareader-vs-dataset-the-real-question.aspx … Read more