 |
|
VB.Net สอบถามการเก็บข้อมูลลง Database ครับ และการเขียน Code แสดง Combobox หลาย ๆ Combobox |
|
 |
|
|
 |
 |
|
3 Days ago ไม่มีใครตอบเลยหรอครับนิ - -a
|
 |
 |
 |
 |
Date :
2013-08-04 21:33:20 |
By :
ih4cK |
|
 |
 |
 |
 |
|
|
 |
 |
|
 |
 |
 |
|
|
 |
 |
|
ตอบข้อที่ 1 : เมื่อได้ ID ของตาราง Master แล้วก็เอา ID ของตาราง Master ไป save ลงในตาราง Detail หลาย ๆ rows
ตอบข้อที่ 2 : ไปศึกษาเรื่อง Binding ครับ
|
ประวัติการแก้ไข 2013-08-04 22:12:40
 |
 |
 |
 |
Date :
2013-08-04 22:12:17 |
By :
01000010 |
|
 |
 |
 |
 |
|
|
 |
 |
|
 |
 |
 |
|
|
 |
 |
|
ดันหน่อยครับ อยากรู้!
|
 |
 |
 |
 |
Date :
2013-08-09 10:57:20 |
By :
ME |
|
 |
 |
 |
 |
|
|
 |
 |
|
 |
 |
 |
|
|
 |
 |
|
ไม่รู้ว่าจะตรงกับความคิดคุณ หรือปล่าว ลองเอาcode ที่ผมเขียนให้ไปลองทำดูน่ะครับ
Imports System.Data.OleDb
Public Class Form1
Dim constr As String = "Provider=Microsoft.ACE.oledb.12.0;Data source= " & Application.StartupPath & "\db.accdb"
Dim con As OleDbConnection
Dim cmd As OleDbCommand
Dim adapter As OleDbDataAdapter
Dim ds As New DataSet
Private Sub connection()
con = New OleDbConnection(constr)
With con
If .State = ConnectionState.Open Then .Close()
con.Open()
End With
End Sub
Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
ShowDataInCombobox1()
End Sub
Private Sub ButtonX1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles ButtonX1.Click
connection()
Dim sql As String = ""
sql = "INSERT INTO DetailPrinter VALUES ('" & TextBoxX1.Text & "','" & ComboBoxEx1.SelectedValue & "','" & ComboBoxEx2.SelectedValue & "','" & ComboBoxEx3.SelectedValue & "')"
cmd = New OleDbCommand
With cmd
.CommandType = CommandType.Text
.Connection = con
.CommandText = sql
.ExecuteNonQuery()
End With
MsgBox("Saved")
End Sub
Private Sub ShowDataInCombobox1()
connection()
Dim sql As String = ""
sql = "select * from Ink"
cmd = New OleDbCommand(sql, con)
adapter = New OleDbDataAdapter(cmd)
ds = New DataSet
adapter.Fill(ds, "kk")
With ComboBoxEx1
.DataSource = ds.Tables("kk")
.ValueMember = "InkID"
.DisplayMember = "InkName"
.SelectedIndex = 0
End With
With ComboBoxEx2
.DataSource = ds.Tables("kk")
.ValueMember = "InkID"
.DisplayMember = "InkName"
.SelectedIndex = 0
End With
With ComboBoxEx3
.DataSource = ds.Tables("kk")
.ValueMember = "InkID"
.DisplayMember = "InkName"
.SelectedIndex = 0
End With
End Sub
Private Sub ComboBoxEx1_SelectedIndexChanged(ByVal sender As Object, ByVal e As System.EventArgs) Handles ComboBoxEx1.SelectedIndexChanged
ComboBoxEx2.SelectedValue = ComboBoxEx1.SelectedValue
ComboBoxEx3.SelectedValue = ComboBoxEx1.SelectedValue
End Sub
End Class
|
 |
 |
 |
 |
Date :
2013-08-09 14:17:04 |
By :
keooudone |
|
 |
 |
 |
 |
|
|
 |
 |
|
 |
 |
 |
|
|
 |
 |
|
ขอโทษด้วย ครับที่อ่านคำถามไม่ละเอียด แก้ให้ใหม่ครับ
Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
ShowDataInCombobox1()
ShowDataInCombobox2()
ShowDataInCombobox3()
End Sub
Private Sub ShowDataInCombobox1()
connection()
Dim sql As String = ""
sql = "select * from Ink"
cmd = New OleDbCommand(sql, con)
adapter = New OleDbDataAdapter(cmd)
ds = New DataSet
adapter.Fill(ds, "kk")
With ComboBoxEx1
.DataSource = ds.Tables("kk")
.ValueMember = "InkID"
.DisplayMember = "InkName"
.SelectedIndex = 0
End With
End Sub
Private Sub ShowDataInCombobox2()
connection()
Dim sql As String = ""
sql = "select * from Ink"
cmd = New OleDbCommand(sql, con)
adapter = New OleDbDataAdapter(cmd)
ds = New DataSet
adapter.Fill(ds, "kk")
With ComboBoxEx2
.DataSource = ds.Tables("kk")
.ValueMember = "InkID"
.DisplayMember = "InkName"
.SelectedIndex = 0
End With
End Sub
Private Sub ShowDataInCombobox3()
connection()
Dim sql As String = ""
sql = "select * from Ink"
cmd = New OleDbCommand(sql, con)
adapter = New OleDbDataAdapter(cmd)
ds = New DataSet
adapter.Fill(ds, "kk")
With ComboBoxEx3
.DataSource = ds.Tables("kk")
.ValueMember = "InkID"
.DisplayMember = "InkName"
.SelectedIndex = 0
End With
End Sub
|
 |
 |
 |
 |
Date :
2013-08-10 11:52:03 |
By :
keooudone |
|
 |
 |
 |
 |
|
|
 |
 |
|
 |
 |
 |
|
|
 |
 |
|
Code (VB.NET)
Imports System.Data.OleDb
Public Class Form1
Dim constr As String = "Provider=Microsoft.ACE.oledb.12.0;Data source= " & Application.StartupPath & "\db.accdb"
Dim con As OleDbConnection
Dim cmd As OleDbCommand
Dim adapter As OleDbDataAdapter
Dim ds As New DataSet
Private Sub connection()
con = New OleDbConnection(constr)
With con
If .State = ConnectionState.Open Then .Close()
con.Open()
End With
End Sub
Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
ShowDataInCombobox1()
ShowDataInCombobox2()
ShowDataInCombobox3()
End Sub
Private Sub ButtonX1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles ButtonX1.Click
connection()
Dim sql As String = ""
sql = "INSERT INTO Ink VALUES ('" & TextBoxX1.Text & "','" & ComboBoxEx1.SelectedValue & "','" & ComboBoxEx2.SelectedValue & "','" & ComboBoxEx3.SelectedValue & "')"
cmd = New OleDbCommand
With cmd
.CommandType = CommandType.Text
.Connection = con
.CommandText = sql
.ExecuteNonQuery()
End With
MsgBox("Saved")
End Sub
Private Sub ShowDataInCombobox1()
connection()
Dim sql As String = ""
sql = "select * from Ink"
cmd = New OleDbCommand(sql, con)
adapter = New OleDbDataAdapter(cmd)
ds = New DataSet
adapter.Fill(ds, "kk")
With ComboBoxEx1
.DataSource = ds.Tables("kk")
.ValueMember = "InkID"
.DisplayMember = "InkName"
.SelectedIndex = 0
End With
End Sub
Private Sub ShowDataInCombobox2()
connection()
Dim sql As String = ""
sql = "select * from Ink"
cmd = New OleDbCommand(sql, con)
adapter = New OleDbDataAdapter(cmd)
ds = New DataSet
adapter.Fill(ds, "kk")
With ComboBoxEx2
.DataSource = ds.Tables("kk")
.ValueMember = "InkID"
.DisplayMember = "InkName"
.SelectedIndex = 0
End With
End Sub
Private Sub ShowDataInCombobox3()
connection()
Dim sql As String = ""
sql = "select * from Ink"
cmd = New OleDbCommand(sql, con)
adapter = New OleDbDataAdapter(cmd)
ds = New DataSet
adapter.Fill(ds, "kk")
With ComboBoxEx3
.DataSource = ds.Tables("kk")
.ValueMember = "InkID"
.DisplayMember = "InkName"
.SelectedIndex = 0
End With
End Sub
End Class
|
 |
 |
 |
 |
Date :
2013-08-10 11:57:32 |
By :
keooudone |
|
 |
 |
 |
 |
|
|
 |
 |
|
 |
 |
|
|