Presentation is loading. Please wait.

Presentation is loading. Please wait.

購物範例.

Similar presentations


Presentation on theme: "購物範例."— Presentation transcript:

1 購物範例

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

3 Form_Load ‘ 本表單全域物件 Dim dt As New DataTable("") 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指令 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


Download ppt "購物範例."

Similar presentations


Ads by Google