public static DataTable GetDataTable(string sqlStr, params SqlParameter[] paras)
{
SqlCommand cmd = new SqlCommand(sqlStr, conn);
if (paras !=null && paras.Length > 0)
{
cmd.Parameters.AddRange(paras);
}
SqlDataAdapter da = new SqlDataAdapter(cmd);
DataTable dt = new DataTable();
try
{
da.Fill(dt);
}
catch (Exception ex)
{
throw ex;
}
return dt;
}
private void LoadBooks()
{
string sqlStr = "select * from Book";
DataTable dt = SqlHelper.GetDataTable(sqlStr);
dgvBooks.DataSource = dt;
MessageBox.Show(dt.Rows.Count.ToString ());
}