I
InBigTrouble
As my previous Post I am a terrible programmer but giving it my best
shot. I’ve used the following code to bind the data from an access
database to text boxes in Windows Form in VB.Net. Now I want to be
able to add to the records using via text boxes. I thought the best
way would be to have a clear screen button that removes all data then
enter details then have a save button. Is this really my only option.
If so can anyone help me on the coding part?
Private Sub frmmemberdetails_Load(ByVal sender As System.Object,
ByVal e As System.EventArgs) Handles MyBase.Load
Me.OpenConnection()
Me.BindToTextbox()
End Sub
Public Sub OpenConnection()
Dim strPath As String = "C:\db1.mdb"
Dim strConnectionString As String =
"Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" & strPath
Dim objOleDbConnection As New
OleDbConnection(strConnectionString)
objOleDbConnection.Open()
Me._AmarsConnection = objOleDbConnection
End Sub
Public Sub BindToTextbox()
Dim strQuery As String = "SELECT * FROM [MemberDetails];"
Dim objOleDbCommand As New OleDbCommand(strQuery,
_AmarsConnection)
Dim objOleDbDataAdapter As New
OleDbDataAdapter(objOleDbCommand)
Dim objDataTable As New DataTable()
Try
objOleDbDataAdapter.Fill(objDataTable)
Me.txtmemberid.DataBindings.Add(New Binding("Text",
objDataTable, "MemberID"))
Me.txtfirstname.DataBindings.Add(New Binding("Text",
objDataTable, "FirstName"))
Me.txtlastname.DataBindings.Add(New Binding("Text",
objDataTable, "LastName"))
Me.txthouseno.DataBindings.Add(New Binding("Text",
objDataTable, "HouseNumber/Name"))
Me.txtstreetname.DataBindings.Add(New Binding("Text",
objDataTable, "StreetName"))
Me.txtarea.DataBindings.Add(New Binding("Text",
objDataTable, "Town"))
'city combobox
Me.txtpostcode.DataBindings.Add(New Binding("Text",
objDataTable, "PostCode"))
Me.txtemail.DataBindings.Add(New Binding("Text",
objDataTable, "MemberE-mail"))
Me.txthomeno.DataBindings.Add(New Binding("Text",
objDataTable, "HomeTel"))
Me.txtmobile.DataBindings.Add(New Binding("Text",
objDataTable, "MobileNumber"))
Me.txtdob.DataBindings.Add(New Binding("Text",
objDataTable, "DateOfBirth"))
Me.txtdatejoined.DataBindings.Add(New Binding("Text",
objDataTable, "DateJoined"))
Me.txtkinname.DataBindings.Add(New Binding("Text",
objDataTable, "NextOfKin-Name"))
Me.txtkinno.DataBindings.Add(New Binding("Text",
objDataTable, "NextOfKin-Tel"))
Catch ex As Exception
Me.ComboBox1.Text = ex.Message.ToString()
Finally
Me.CloseConnection()
End Try
End Sub
Sub CloseConnection()
_AmarsConnection.Close()
End Sub
End Class
shot. I’ve used the following code to bind the data from an access
database to text boxes in Windows Form in VB.Net. Now I want to be
able to add to the records using via text boxes. I thought the best
way would be to have a clear screen button that removes all data then
enter details then have a save button. Is this really my only option.
If so can anyone help me on the coding part?
Private Sub frmmemberdetails_Load(ByVal sender As System.Object,
ByVal e As System.EventArgs) Handles MyBase.Load
Me.OpenConnection()
Me.BindToTextbox()
End Sub
Public Sub OpenConnection()
Dim strPath As String = "C:\db1.mdb"
Dim strConnectionString As String =
"Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" & strPath
Dim objOleDbConnection As New
OleDbConnection(strConnectionString)
objOleDbConnection.Open()
Me._AmarsConnection = objOleDbConnection
End Sub
Public Sub BindToTextbox()
Dim strQuery As String = "SELECT * FROM [MemberDetails];"
Dim objOleDbCommand As New OleDbCommand(strQuery,
_AmarsConnection)
Dim objOleDbDataAdapter As New
OleDbDataAdapter(objOleDbCommand)
Dim objDataTable As New DataTable()
Try
objOleDbDataAdapter.Fill(objDataTable)
Me.txtmemberid.DataBindings.Add(New Binding("Text",
objDataTable, "MemberID"))
Me.txtfirstname.DataBindings.Add(New Binding("Text",
objDataTable, "FirstName"))
Me.txtlastname.DataBindings.Add(New Binding("Text",
objDataTable, "LastName"))
Me.txthouseno.DataBindings.Add(New Binding("Text",
objDataTable, "HouseNumber/Name"))
Me.txtstreetname.DataBindings.Add(New Binding("Text",
objDataTable, "StreetName"))
Me.txtarea.DataBindings.Add(New Binding("Text",
objDataTable, "Town"))
'city combobox
Me.txtpostcode.DataBindings.Add(New Binding("Text",
objDataTable, "PostCode"))
Me.txtemail.DataBindings.Add(New Binding("Text",
objDataTable, "MemberE-mail"))
Me.txthomeno.DataBindings.Add(New Binding("Text",
objDataTable, "HomeTel"))
Me.txtmobile.DataBindings.Add(New Binding("Text",
objDataTable, "MobileNumber"))
Me.txtdob.DataBindings.Add(New Binding("Text",
objDataTable, "DateOfBirth"))
Me.txtdatejoined.DataBindings.Add(New Binding("Text",
objDataTable, "DateJoined"))
Me.txtkinname.DataBindings.Add(New Binding("Text",
objDataTable, "NextOfKin-Name"))
Me.txtkinno.DataBindings.Add(New Binding("Text",
objDataTable, "NextOfKin-Tel"))
Catch ex As Exception
Me.ComboBox1.Text = ex.Message.ToString()
Finally
Me.CloseConnection()
End Try
End Sub
Sub CloseConnection()
_AmarsConnection.Close()
End Sub
End Class