1 / 8

購物範例

購物範例. 步驟一:建立 UI. 一個 combobox + ㄧ個 TextBox+ ㄧ個 Gridview 物件 二個 Button 物件. Form_Load. ‘ 本表單全域物件 Dim dt As New DataTable("") dt.Columns.Add(" 產品編號 ") dt.Columns.Add(" 產品名稱 ") dt.Columns.Add(" 數量 "). 設定 ComboBox. 設定 ComboBox. 設定 ComboBox. 設定 ComboBox.

tsun
Download Presentation

購物範例

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. 購物範例

  2. 步驟一:建立UI 一個combobox + ㄧ個TextBox+ㄧ個Gridview 物件 二個Button物件

  3. Form_Load ‘ 本表單全域物件 Dim dt As New DataTable("") dt.Columns.Add("產品編號") dt.Columns.Add("產品名稱") dt.Columns.Add("數量")

  4. 設定ComboBox

  5. 設定ComboBox

  6. 設定ComboBox

  7. 設定ComboBox Private Sub ComboBox1_SelectedIndexChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles ComboBox1.SelectedIndexChanged p_id = ComboBox1.SelectedValue.ToString() p_name = ComboBox1.Text End Sub Dim p_id, p_name As String ‘ 加入按鈕 Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click dt.Rows.Add(New Object() {p_id, p_name, TextBox1.Text}) DataGridView1.DataSource = dt End Sub

  8. 確定購買 Dim i As Integer For i = 1 To DataGridView1.RowCount - 1 'DataGridView1.Rows(i - 1).Cells(0).Value.ToString() ' 一.connection物件 '1.宣告 Dim dbconn As OleDbConnection '2.產生物件並給定參數 dbconn = New OleDbConnection("Provider=Microsoft.Jet.OLEDB.4.0;Data Source=teacher.mdb;User Id=admin;Password=;") dbconn.Open() '二.command物件執行sql指令 '1.宣告 Dim dbcmd As New OleDbCommand '2.產生並執行sql指令 dbcmd.CommandType = CommandType.Text dbcmd.CommandText = "insert into sales (c_id,p_id,amount,s_day) values (1," + DataGridView1.Rows(i - 1).Cells(0).Value + "," + DataGridView1.Rows(i - 1).Cells(2).Value + ",'" + System.DateTime.Today.ToString() + "')" dbcmd.Connection = dbconn dbcmd.ExecuteNonQuery() dbconn.Close() Next

More Related