Private Sub DataGrid1_DblClick()
Dim g_Conn As New ADODB.Connection
Dim rs As New ADODB.Recordset
m_strConn = "Provider=SQLOLEDB.1;Integrated Security=SSPI;Persist Security Info=False;Initial Catalog=test;Data Source=COM"
g_Conn.Open m_strConn
If rs.State = adStateOpen Then rs.Close
strSql = "SELECT * FROM emp"
rs.Open strSql, g_Conn, adOpenKeyset, adLockOptimistic Text1.Text = rs!IDNO
End Sub
มันก็ถูกแล้วนะ ปกติใช้แต่AdodcครับT^T
Public Class Test
Const C_TABLE = "ReqPayHead"
Public Sub InitialControls()
bsMain.DataMember = C_TABLE
z_ReqNo.DataBindings.Add(New Binding("Text", bsMain, "ReqNo"))
z_ReqAmt.DataBindings.Add(New Binding("Text", bsMain, "ReqAmt", True, System.Windows.Forms.DataSourceUpdateMode.OnValidation, Nothing, "N2"))
End Sub
Public Sub LoadData()
Dim sqlCn As New SqlClient.SqlConnection(My.Settings.TestConString)
Try
sqlCn.Open()
Dim SQL As String
SQL = "SELECT TOP 100 t.ReqHeadID, t.ReqNo, t.Status, t.ReqAmt, t.dtInsert FROM VW_ReqPayHead t"
Dim da As New SqlClient.SqlDataAdapter(SQL, sqlCn)
If dsMain.Tables.Contains(C_TABLE) Then dsMain.Tables(C_TABLE).Rows.Clear()
da.Fill(dsMain, C_TABLE)
Catch ex As Exception
Throw ex
Finally
sqlCn.Close() : sqlCn.Dispose()
End Try
End Sub
Private Sub Test_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
Try
LoadData()
InitialControls()
Catch ex As Exception
MessageBox.Show(ex.Message)
End Try
End Sub
End Class
Public cn As ADODB.Connection
Public RS As ADODB.Recordset
Sub fillcombo()
Set RS = New ADODB.Recordset
Set cn = New ADODB.Connection
cn.ConnectionString = "Provider = Microsoft.Jet.OLEDB.4.0;Data Source= " & (App.Path & "\time3.mdb") & "; persist security info = false"
cn.Open
RS.Open "select * from Table1 ", cn, adOpenStatic, adLockPessimistic
'RS.Requery
While RS.EOF = False
Combo1.AddItem RS!DateNow
RS.MoveNext
Wend
RS.Close
Set RS = Nothing
End Sub
Private Sub Combo1_Click()
Set cn = New ADODB.Connection
Set RS = New ADODB.Recordset
cn.ConnectionString = "Provider = Microsoft.Jet.OLEDB.4.0;Data Source= " & (App.Path & "\time3.mdb") & "; persist security info = false"
cn.Open
RS.Open "select * from Table1 where DateNow = '" & Combo1.Text & "'", cn, 3, 3
If Not RS.EOF Then
Me.Combo1.Text = RS!DateNow
End If
Set RS = Nothing
End Sub
Private Sub Command3_Click()
Dim find As String
find = Combo1.Text
Adodc1.Recordset.find "DateNow =" & find
End Sub
Private Sub DataGrid1_Click()
Set cn = New ADODB.Connection
Set RS = New ADODB.Recordset
cn.ConnectionString = "Provider = Microsoft.Jet.OLEDB.4.0;Data Source= " & (App.Path & "\time3.mdb") & "; persist security info = false"
cn.Open
RS.Open "select * from Table1 where DateNow = '" & Combo1.Text & "'", cn, 3, 3
End Sub
Private Sub Form_Load()
Me.fillcombo
End Sub