 |
|
ช่วยแนะนำวิธีการดึงข้อมูลจาก database มาใส่ในตัว combobox หน่อยครับ |
|
 |
|
|
 |
 |
|
Code (VB.NET)
Con = New OracleConnection(StrCon)
Try
Con.Open()
If Con.State = ConnectionState.Open Then
Dim StrSql As String = "SELECT br_no , br_name FROM tbl_branch ORDER BY br_no ASC"
Da.MissingSchemaAction = MissingSchemaAction.AddWithKey
Da.SelectCommand = New OracleCommand(StrSql, Con)
Try
Da.Fill(Ds, "branch")
With Combo_Branch
.DataSource = Ds.Tables("branch")
.DisplayMember = "br_name"
.ValueMember = "br_no"
End With
Ds.Clear()
Con.Close()
Catch ex As Exception
MessageBox.Show(ex.Message, "ERROR", MessageBoxButtons.OK, MessageBoxIcon.Error)
End Try
Else
MessageBox.Show("Oracle Connect Failed", "ERROR", MessageBoxButtons.OK, MessageBoxIcon.Error)
End If
Catch ex As Exception
MessageBox.Show(ex.Message, "ERROR", MessageBoxButtons.OK, MessageBoxIcon.Error)
End Try
จากโค๊ตด้านบนนี้สามารถนำข้อมูลมาใส่ในตัว combo ได้แล้วแต่ผมต้องการให้มีข้อความว่า --- กรุณาเลือก --- ขึ้นก่อนน่ะครับไม่ร้ว่าจะต้องไปเพิ่มหรือใส่โค๊ตตรงไหน
Tag : .NET, Win (Windows App)
|
|
 |
 |
 |
 |
Date :
2012-10-03 10:09:55 |
By :
babyprogrammer |
View :
1353 |
Reply :
4 |
|
 |
 |
 |
 |
|
|
|
 |
 |
|
 |
 |
 |
|
|
 |
 |
|
จากโค๊ตด้านบนนี้สามารถนำข้อมูลมาใส่ในตัว combo ได้แล้วแต่ผมต้องการให้มีข้อความว่า --- กรุณาเลือก --- ขึ้นก่อนน่ะครับไม่ร้ว่าจะต้องไปเพิ่มหรือใส่โค๊ตตรงไหน
แบบง่ายงายเลยนะ ก็ไปเพิ่มใน databese เลยดิ ให้อยุ๋อันเเรกดิ เป้นอันจบ
|
 |
 |
 |
 |
Date :
2012-10-03 13:03:21 |
By :
naruto |
|
 |
 |
 |
 |
|
|
 |
 |
|
 |
 |
 |
|
|
 |
 |
|
อันนั้นพอจะทราบครับ แต่อยากรู้ว่าพอจะมีวิธีอื่นอีกรึป่าว
|
 |
 |
 |
 |
Date :
2012-10-03 13:38:35 |
By :
babyprogrammer |
|
 |
 |
 |
 |
|
|
 |
 |
|
 |
 |
 |
|
|
 |
 |
|
ลองปรับดูนะครับ ไม่ค่อยตรงแต่อาจจะพอช่วยได้
Private Sub GetDriver2DDL()
Try
objConn = New SqlConnection(sysconfig)
If (objConn.State = ConnectionState.Open) Then
objConn.Close()
End If
objConn.Open()
Dim sqlDriver As String
Dim dt As New DataTable
sqlDriver = "--- SQL Select --- '"
objCmd = New SqlCommand(sqlDriver, objConn)
dtAdapter = New SqlDataAdapter(objCmd)
dtAdapter.Fill(dt)
If dt.Rows.Count > 0 Then
ddlDriverEditForm.DataSource = dt
ddlDriverEditForm.DataTextField = "br_name"
ddlDriverEditForm.DataValueField = "br_no"
ddlDriverEditForm.DataBind()
ddlDriverEditForm.Items.Insert(0, "-- กรุณาเลือก --")
End If
Catch ex As Exception
Finally
objConn.Close()
End Try
End Sub
|
 |
 |
 |
 |
Date :
2012-10-03 16:33:03 |
By :
Nebula |
|
 |
 |
 |
 |
|
|
 |
 |
|
 |
 |
 |
|
|
 |
 |
|
Code (VB.NET)
Con = New OracleConnection(StrCon)
Try
Con.Open()
If Con.State = ConnectionState.Open Then
Dim StrSql As String = "SELECT br_no , br_name FROM tbl_branch ORDER BY br_no ASC"
Da.MissingSchemaAction = MissingSchemaAction.AddWithKey
Da.SelectCommand = New OracleCommand(StrSql, Con)
Try
Da.Fill(Ds, "branch")
'เพิ่มตรงนี้ ครับ ไม่รู้เขียนถูกหรือเปล่า แต่ก็น่า จะ ประมาณนี้ ครับ
Dim _dt as new Datatable
Dim _dr as Datarow
_dt = Ds.Tables("branch")
_dr = _dt.Newrow()
_dr("br_no") = "0"
_dr("br_name") = "---กรุณาเลือก---"
With Combo_Branch
.DataSource = _dt ' เปลี่ยน เป็น _dt
.DisplayMember = "br_name"
.ValueMember = "br_no"
End With
Ds.Clear()
Con.Close()
Catch ex As Exception
MessageBox.Show(ex.Message, "ERROR", MessageBoxButtons.OK, MessageBoxIcon.Error)
End Try
Else
MessageBox.Show("Oracle Connect Failed", "ERROR", MessageBoxButtons.OK, MessageBoxIcon.Error)
End If
Catch ex As Exception
MessageBox.Show(ex.Message, "ERROR", MessageBoxButtons.OK, MessageBoxIcon.Error)
End Try
|
ประวัติการแก้ไข 2012-10-03 17:12:44
 |
 |
 |
 |
Date :
2012-10-03 17:12:21 |
By :
lee_latee |
|
 |
 |
 |
 |
|
|
 |
 |
|
 |
 |
|
|