You might have started using .Net 4.0 and Visual Studio 2010. But are you sure that you all are using most of the advance features of .Net or still you are using the same boring .Net 1.1 features, as someone said "Old Wine in New Bottle". If so, I think this article will help you to implement some new features available in .Net 2.0/3.5/4.0.
Abstract
This article will guide you to migrate your application from 2-Tier architecture (was possible in VB6.0, .Net 1.0/1.1) to the most advance Data Access methodology available in .Net 4.0.
Please keep watching all migration articles one by one. If it really helps you out then please don't forget to put your feedback and comments.
Old Wine in New Bottle
If you are writing all the data access logic inside your code behind, I guess your code looks like this.
- While Inserting Data into Database:
SqlConnection sqlConnection =
new SqlConnection
(ConfigurationManager.ConnectionStrings["EmployeeConString"].ConnectionString);SqlCommand sqlCommand =
new SqlCommand
(string.Format("INSERT INTO Department
(DepartmentId, Name, Budget, StartDate) VALUES ({0}, '{1}', {2}, '{3}')",
txtDeptId.Text, txtDeptName.Text, txtBudget.Text, txtStartDate.Text), sqlConnection);sqlConnection.Open();
sqlCommand.ExecuteNonQuery();
sqlConnection.Close();
- While Binding Data to ComboBox /DropDownList:
SqlConnection sqlConnection =
new SqlConnection
(ConfigurationManager.ConnectionStrings["EmployeeConString"].ConnectionString);
SqlDataAdapter sqlDataAdapter =
new SqlDataAdapter
("SELECT DepartmentId, Name FROM Department", sqlConnection);DataTable deptList = new DataTable("Department");
sqlDataAdapter.Fill(deptList);cmbDepartment.DataSource = deptList;
cmbDepartment.DisplayMember = "Name";
cmbDepartment.ValueMember = "DepartmentId";
OR
- While Binding Data to DataGridView:
SqlConnection sqlConnection =
new SqlConnection
(ConfigurationManager.ConnectionStrings["EmployeeConString"].ConnectionString);
SqlCommand sqlCommand =
new SqlCommand
("SELECT DepartmentId, Name FROM Department", sqlConnection);sqlConnection.Open();
SqlDataReader dataReader = sqlCommand.ExecuteReader();while (dataReader.Read())
cmbDepartment.Items.Add(dataReader["Name"].ToString());dataReader.Close();
- While Binding Data to ListView:
SqlConnection sqlConnection =
new SqlConnection
(ConfigurationManager.ConnectionStrings["EmployeeConString"].ConnectionString);
SqlCommand sqlCommand =
new SqlCommand
("SELECT DepartmentId, Name, Budget, StartDate FROM Department", sqlConnection);sqlConnection.Open();
SqlDataReader dataReader = sqlCommand.ExecuteReader();while (dataReader.Read())
{
ListViewItem item = new ListViewItem(dataReader["DepartmentId"].ToString());
item.SubItems.Add(dataReader["Name"].ToString());
item.SubItems.Add(dataReader["Budget"].ToString());
item.SubItems.Add(dataReader["StartDate"].ToString());lvwDepartment.Items.Add(item);
}
dataReader.Close();



Muhammad UsmanPosted Jun 16, 2017, 2:05 AM
Good site good thing
vijay kumarPosted Mar 4, 2015, 12:40 PM
best article.........
Rohatash KumarPosted Aug 9, 2011, 11:56 PM
Good Article. keep it up....
Dharma BPosted Dec 9, 2010, 1:08 AM
Thanks it's really help me. but m not found Part II plz tell me.