[RESOLVED] [2005] Simple CODE
I am current still learning in database, and i figure some of this hard to code.
This is how i add a record in a access using VB6.0
Code:
Call Opening
ObjRS.Open "Contact", ObjConn, adLockOptimistic, adOpenStatic, adCmdTable
ObjRs.AddNew
ObjRs.Fileds("Sname") = txtName.Text
ObjRs.Fields("Number") = txtNumber.Text
ObjRs.Fields("Address") = txtAddress.Text
ObjRs.Update
MsgBox ("Record Added")
Call Closing
its very simple but when im using VB.Net using this code
Code:
Option Strict On
Option Explicit On
Imports System.Windows.Forms.Form
Imports System.Data.OleDb
Public Class CreateAccount
Private contactID As Int64 = 0
Public Property Contact() As Int64 '
Get
Return contactID
End Get
Set(ByVal value As Int64)
contactID = value
End Set
End Property
Public Sub RetriveRecords()
Dim ObjConn As New OleDbConnection("Provider = Microsoft.Jet.OleDb.4.0;Data Source=C:\Documents and Settings\Administrator\Desktop\DBase\Bank.mdb;")
Dim dAdapter As New OleDbDataAdapter("SELECT * FROM UserDatabase", ObjConn)
Dim dTable As New DataTable
dAdapter.Fill(dTable)
Database.AccessDatabase.DataSource = dTable
End Sub
Private Sub btnSave_CLick(ByVal sender As Object, ByVal e As EventArgs) Handles btnSave.Click
Dim ObjConn As New OleDbConnection("Provider = Microsoft.Jet.OleDb.4.0;Data Source=C:\Documents and Settings\Administrator\Desktop\DBase\Bank.mdb;")
Dim sql As String = String.Empty
If contactID = 0 Then
sql = "INSERT INTO UserDatabase(Ename,Address,ContactNumber,AmountPaid,DatePaid,PeriodTime)" _
& "VALUES('" & txtEname.Text & "','" & txtAddress.Text & "','" & txtContact.Text & "','" & txtAmount.Text & "','" & txtDate.Text & "','" & cboPeriod.Text & "')"
End If
ObjConn.Open()
Dim dCMd As New OleDbCommand(sql, ObjConn)
dCMd.ExecuteNonQuery()
ObjConn.Close()
MessageBox.Show("Record Added")
I use the Public Property to determine what im going to do. Is there any simple code reather than that. As simple in VB6.0