Danh mục

Practical Database Programming With Visual C#.NET- P7

Số trang: 50      Loại file: pdf      Dung lượng: 773.72 KB      Lượt xem: 12      Lượt tải: 0    
Thu Hiền

Phí tải xuống: 10,000 VND Tải xuống file đầy đủ (50 trang) 0
Xem trước 5 trang đầu tiên của tài liệu này:

Thông tin tài liệu:

Tham khảo tài liệu practical database programming with visual c#.net- p7, công nghệ thông tin, cơ sở dữ liệu phục vụ nhu cầu học tập, nghiên cứu và làm việc hiệu quả
Nội dung trích xuất từ tài liệu:
Practical Database Programming With Visual C#.NET- P7 5.18 Query Data Using Runtime Objects to Microsoft Access 2007 Database 323 AccessSelectRTObject.FacultyForm ShowFaculty() private string ShowFaculty(string fName) {A string strName;B switch (fName) { case Black Anderson: strName = Anderson.jpg; break; case Ying Bai: strName = Bai.jpg; break; case Satish Bhalla: strName = Satish.jpg; break; case Steve Johnson: strName = Johnson.jpg; break; case Jenney King: strName = King.jpg; break; case Alice Brown: strName = Brown.jpg; break; case Debby Angles: strName = Angles.jpg; break; case Jeff Henry: strName = Henry.jpg; break;C default: strName = No Match; break; }D if (strName != No Match) { PhotoBox.SizeMode = PictureBoxSizeMode.StretchImage; PhotoBox.Image = System.Drawing.Image.FromFile(strName); }E return strName; }Figure 5.87 Coding for the ShowFaculty method. AccessSelectRTObject.FacultyForm cmdBack_Click() private void cmdBack_Click(object sender, EventArgs e) { this.Hide(); } 359Figure 5.88 Coding for the cmdBack button Click method.faculty. Five label controls bound to the associated columns in the Faculty table areupdated with the queried information, and the selected faculty image is also displayed inthe PhotoBox control, which is shown in Figure 5.89. You can try to select the differentmethod by clicking on the drop-down arrow from the Method combobox. Yes, the projectworks fine with all three methods without any problem at all!324 Chapter 5 Data Selection Query with Visual C#.NETFigure 5.89 Running status of the Faculty form. Our next job is to do the coding for the Course form.5.18.4 Query Data Using Runtime Objects for Course FormThree data query methods will be used for the data query on this form: DataAdapter,DataReader, and LINQ method. As we did for the FacultyForm, we also need to use theOleDb data provider to perform the data query in this CourseForm. Thus, first we needto add one more namespace, System.Data.OleDb, into the namespace section on the codewindow of this form. Open the code window and add using System.Data.OleDb;to the namespace part of this form. Next we need to create a class-level textbox array, CourseTextBox[6], and a classlevel DataSet object ds. The textbox array is used to temporarily save five columns in theCourse data table, and we need this array when we retrieve and assign columns to theassociated textbox controls on the CourseForm window as the project runs. The dsDataSet is used for the LINQ method since there is no direct relationship between theLINQ and Access database, and we need this DataSet to perform a LINQ to DataSetoperation to do the data query (refer to Figure 5.90). Now we need to do the coding for the constructor of the CourseForm to do someinitialization tasks. Enter the codes into the constructor, and your finished coding shouldmatch that shown in Figure 5.90. Let’s see how this piece of code works. A. The namespace System.Data.OleDb is added here since we need to use this OleDb Data Provider to perform the data query in this form. B. This coding fragment is very similar to the one we did for the Faculty form. The only dif- ference is that the Label array has been replaced by a TextBox array since we used 5 textbox controls to display the detailed course information that is related to the selected faculty from the Faculty Name combobox. The Course table has 7 columns, but we only 5.18 Query Data Using Runtime Objects to Microsoft Access 2007 Database 325 AccessSelectRTObject.CourseForm CourseForm using System; using System.Collections.Generic; using System.ComponentModel; using System.Data;A using System.Data.OleDb; using System.Drawing; using System.Linq; using System.Text; using System.Windows.Forms; namespace AccessSelectRTObject { public partial class CourseForm : Form {B private TextBox[] CourseTextBox = new TextBox[6]; DataSet ds = new DataSet(); public CourseForm() { InitializeComponent();C ComboName.Items.Add(Ying Bai); ComboName.Items.Add(Satish Bhalla); ComboName.Items.Add(Black Anderson); ComboName.Items.Add(Steve Johnson); ComboName.Items.Add(Jenney King); ComboName.Items.Add(Alice Brown); ComboName.Items.Add(Debby Angles); ComboName.Items.Add(Jeff Henry); ComboName.SelectedIndex = 0;D ComboMethod.Items.Add(DataAdapter Method); ComboMethod.Items.Add(DataReader Method); ComboMethod.Items.Add(LINQ & DataSet Method); ComboMethod.SelectedIndex = 0; }Figure 5.90 Coding for the constructor of the CourseForm. need six of them, so the size of this TextBox array is 6 and each element or each TextBox control in this array is indexed f ...

Tài liệu được xem nhiều: