Private Sub Form_Load()
Set con = New ADODB.Connection
Set rs = New ADODB.Recordset
con.Open "Provider=MSDAORA.1;Password=tiger;User ID=system;Persist Security Info=True"
rs.ActiveConnection = con
rs.CursorType = adOpenDynamic
rs.Source = "select * from login"
rs.Open
un = rs.Fields(0).Value
pw = rs.Fields(1).Value
rs.Close
Thanks & Regards,
RAJESH KUMAR.R
End SubIt can be possible with CurrencyManager. Each windows form can have a BindingContext object. It can have number of CurrencyManager objects for each table you are using in the application. By using this it is easy to bind the controls to DB columns and navigations can also be made easy.
Check the folloging code.
Dim cm As CurrencyManager
Private Sub btnAdd_Click(ByVal sender As System.Object, ByVal e As System.EventArgs)
cm.AddNew()
txtNumber.Focus()
End Sub
Private Sub frmDatabase_Load(ByVal sender As System.Object, ByVal e As System.EventArgs)
DAdapterObj.SelectCommand.CommandText = "select id, name from employee"
DAdapterObj.SelectCommand.Connection = connObj
DAdapterObj.MissingSchemaAction = MissingSchemaAction.AddWithKey
DAdapterObj.Fill(dsObj, "employee")
cm = Me.BindingContext(dsObj.Tables("employee"))
txtNumber.DataBindings.Add("Text", dsObj.Tables("employee"), "id")
txtName.DataBindings.Add("Text", dsObj.Tables("employee"), "name")
cbObj = New MySqlCommandBuilder(DAdapterObj)
dgEmployee.DataSource = dsObj.Tables("employee")
End Sub
Private Sub btnUpdate_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnSave.Click
cm.EndCurrentEdit()
cm.Position = 0
End Sub
Private Sub frmDatabase_Closed(ByVal sender As Object, ByVal e As System.EventArgs) Handles MyBase.Closed
connObj.Open()
DAdapterObj.Update(dsObj.Tables("employee"))
connObj.Close()
End Sub
Private Sub btnFirst_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles btnFirst.Click
cm.Position = 0
End Sub
Private Sub btnPrevious_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnPrevious.Click
If cm.Position > 0 Then
cm.Position -= 1
Else : MsgBox("This is the first record!", MsgBoxStyle.Information)
End If
End Sub
Private Sub btnNext_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnNext.Click
If cm.Position < cm.Count Then
cm.Position += 1
Else : MsgBox("This is the last record!", MsgBoxStyle.Information)
End If
End Sub
Private Sub btnLast_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnLast.Click
cm.Position = cm.Count
End Sub
Private Sub btnCancel_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnCancel.Click
cm.CancelCurrentEdit()
End Sub
Private Sub btnDelete_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnDelete.Click
If cm.Count > 0 Then cm.RemoveAt(cm.Position)
End Sub
Private Sub btnSearch_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnSearch.Click
Dim row As DataRow
row = dsObj.Tables("employee").Rows.Find(txtNumber.Text.Trim)
If row Is Nothing Then
MsgBox("No records found!", MsgBoxStyle.OKOnly)
Else txtName.Text = row.Item(1)
End If
End Sub
Time is Gold
Thanks & Regards,
Rajesh Kumar,
9962038582.
Maheshvishnu, if this helps please login to Mark As Answer. | Alert Moderator