F
Fernando Chilvarguer
I'm new to ADO.NET 2.0 so I have some questions you may be able to help me
with.
1. I decided to take advantage of Strong Typed datasets. Everything worked
but I did not really like the way I had to deal with the TableAdapters. So,
I went ahead and did NOT use the TableAdapters provided by the wizards in
VS2005.
So, my code now looks something like this:
SERVER CODE (class library):
//My typed dataset is named CompanyDS
CompanyDS dataset = new CompanyDS();
string connectionString =
ConfigurationManager.ConnectionStrings["dataBaseConnection"].ConnectionString;
using (SqlConnection conn = new SqlConnection(connectionString))
{
// Create the command and set its properties.
SqlCommand command = new SqlCommand();
command.Connection = conn;
command.CommandText = "sp_SelectCompany";
command.CommandType = CommandType.StoredProcedure;
// Add the input parameter and set its properties.
SqlParameter parameter = new SqlParameter();
parameter.ParameterName = "@CompanyID";
parameter.SqlDbType = SqlDbType.Int;
parameter.Direction = ParameterDirection.Input;
parameter.Value = ID;
command.Parameters.Add(parameter);
//Create the data adapter and populate the dataset
SqlDataAdapter adapter = new SqlDataAdapter();
conn.Open();
adapter.SelectCommand = command;
adapter.Fill(dataset,"Company");
conn.Close();
}
CLIENT CODE:
//My typed dataset is inside a class names "CompanyDAL"
CompanyDAL company = new CompanyDAL();
CompanyDS ds = company.loadCompany(1);
CompanyDS.CompanyDataTable dt = (CompanyDS.CompanyDataTable) ds.Tables[0];
MY QUESTION:
a. Is this an acceptable (best practice) way of doing this or am I way off
on this one?
b. Why do I have to cast my datatable as "CompanyDS.CompanyDataTable"? I
thought the type dataset would have typed tables of type CompanyDataTable
being returned to me.
2. Has anyone used (or use) the Data Access Application Block from Microsoft
Patterns and Practices? If so, is it really productive or is it a little too
much for simpler jobs? I know those are subjective questions, I'm just
trying to gather some input on how the community is using those things
before I dive deep into one way or another of doing things in 2.0
Thanks,
Fernando
with.
1. I decided to take advantage of Strong Typed datasets. Everything worked
but I did not really like the way I had to deal with the TableAdapters. So,
I went ahead and did NOT use the TableAdapters provided by the wizards in
VS2005.
So, my code now looks something like this:
SERVER CODE (class library):
//My typed dataset is named CompanyDS
CompanyDS dataset = new CompanyDS();
string connectionString =
ConfigurationManager.ConnectionStrings["dataBaseConnection"].ConnectionString;
using (SqlConnection conn = new SqlConnection(connectionString))
{
// Create the command and set its properties.
SqlCommand command = new SqlCommand();
command.Connection = conn;
command.CommandText = "sp_SelectCompany";
command.CommandType = CommandType.StoredProcedure;
// Add the input parameter and set its properties.
SqlParameter parameter = new SqlParameter();
parameter.ParameterName = "@CompanyID";
parameter.SqlDbType = SqlDbType.Int;
parameter.Direction = ParameterDirection.Input;
parameter.Value = ID;
command.Parameters.Add(parameter);
//Create the data adapter and populate the dataset
SqlDataAdapter adapter = new SqlDataAdapter();
conn.Open();
adapter.SelectCommand = command;
adapter.Fill(dataset,"Company");
conn.Close();
}
CLIENT CODE:
//My typed dataset is inside a class names "CompanyDAL"
CompanyDAL company = new CompanyDAL();
CompanyDS ds = company.loadCompany(1);
CompanyDS.CompanyDataTable dt = (CompanyDS.CompanyDataTable) ds.Tables[0];
MY QUESTION:
a. Is this an acceptable (best practice) way of doing this or am I way off
on this one?
b. Why do I have to cast my datatable as "CompanyDS.CompanyDataTable"? I
thought the type dataset would have typed tables of type CompanyDataTable
being returned to me.
2. Has anyone used (or use) the Data Access Application Block from Microsoft
Patterns and Practices? If so, is it really productive or is it a little too
much for simpler jobs? I know those are subjective questions, I'm just
trying to gather some input on how the community is using those things
before I dive deep into one way or another of doing things in 2.0
Thanks,
Fernando