Hướng dẫn sử dụng DataGridView control

Hướng dẫn sử dụng DataGridView control

Tạo ứng dụng Windows Application.

Chú ý: Trong form phải using namespace System.Data.SqlClient để có thể kết nối với CSDL SQL Server

Bước 1: Tạo đối tượng SqlConnection để kết nối với CSDL

SqlConnection connection = new SqlConnection("server=HUNGCUONG\\SQLEXPRESS;database=winform;uid=sa;pwd=123456");

//Buoc 2: Tao doi tuong SqlDataAdapter

SqlDataAdapter adapter = new SqlDataAdapter("select * from nhanvien", connection);

//Buoc 3: Tao DataSet

DataSet dsVoLam = new DataSet();

//Buoc 4: Fill du lieu vao DataSet

adapter.Fill(dsVoLam, "TonyHungThang");

//Buoc 5: Fill du lieu vao DataGridView

Từ cửa sổ ToolBox, kéo thả control DataGridView vào form, sau đó binding dữ liệu vào control này.

dgrvwVoLam.DataSource = dsVoLam.Tables["TonyHungThang"];

Sau đó chạy chương trình để xem kết quả

Hướng dẫn sử dụng DataGridView control

Bài tập:

One of the popular gyms of the city ‘FIGHTMAN’ has decided to create an information system to display each of the equipment available in the gym. This information system will help people to know about the equipments, their names and also their uses.

You need to create an application using Windows Forms with C# language to display the information. A Form should contain a Label, RichTextBox, a button and a Picture box to display image and description of the equipment. The equipments mentioned below should be displayed on the form:

Cardio, Spinner bikes, Treadmill machine etc. User should be allowed to navigate by clicking on button. (See Fig: 1)

File: 
Bạn thấy bài viết này như thế nào?: 
No votes yet
Ảnh của Tommy Tran

Tommy owner Express Magazine

Drupal Developer having 9+ year experience, implementation and having strong knowledge of technical specifications, workflow development. Ability to perform effectively and efficiently in team and individually. Always enthusiastic and interseted to study new technologies

  • Skype ID: tthanhthuy

Advertisement

 

jobsora

Dich vu khu trung tphcm

Dich vu diet chuot tphcm

Dich vu diet con trung

Quảng Cáo Bài Viết

 
Drupal: Không được CLONE THE DATABASE

Drupal: Không được CLONE THE DATABASE

It is generally agreed that cloning the database downstream (that is, from development toward production) is a bad idea, if only because by doing so all production content is lost; most developers use Features,

Facebook muốn tặng không smartphone cho người dùng

Facebook muốn tặng không smartphone cho người dùng

Hôm qua (25/11), trang công nghệ Businessinsider dẫn lời 2 nguồn tin thân cận với dự án Facebook Phone, cho biết giới lãnh đạo mong muốn tặng không dế cưng cho người dùng.

Đại học có phải con đường duy nhất dẫn đến thành công?

Đại học có phải con đường duy nhất dẫn đến thành công?

Đại đa số các bậc phụ huynh, nhà trường khi tư vấn, định hướng cho con em, học sinh về nấc thang kế tiếp của cuộc đời các em, đều chỉ có 1 đích đến mang tên “Đại học”

Công ty diệt chuột T&C

 

Diet con trung