Database Not Updating

Help me to solve this

Page 1 of 1

2 Replies - 1781 Views - Last Post: 19 November 2007 - 06:56 AM Rate Topic: -----

#1 charitharanasingha   User is offline

  • New D.I.C Head

Reputation: 1
  • View blog
  • Posts: 10
  • Joined: 03-May 07

Database Not Updating

Posted 18 November 2007 - 11:10 PM

Public Class Form1
	Inherits System.Windows.Forms.Form

#Region " Windows Form Designer generated code "

	Public Sub New()
		MyBase.New()

		'This call is required by the Windows Form Designer.
		InitializeComponent()

		'Add any initialization after the InitializeComponent() call

	End Sub

	'Form overrides dispose to clean up the component list.
	Protected Overloads Overrides Sub Dispose(ByVal disposing As Boolean)
		If disposing Then
			If Not (components Is Nothing) Then
				components.Dispose()
			End If
		End If
		MyBase.Dispose(disposing)
	End Sub

	'Required by the Windows Form Designer
	Private components As System.ComponentModel.IContainer

	'NOTE: The following procedure is required by the Windows Form Designer
	'It can be modified using the Windows Form Designer.  
	'Do not modify it using the code editor.
	Friend WithEvents btnDeposit As System.Windows.Forms.Button
	Friend WithEvents btnWithdraw As System.Windows.Forms.Button
	Friend WithEvents btnBalance As System.Windows.Forms.Button
	Friend WithEvents Panel1 As System.Windows.Forms.Panel
	Friend WithEvents PictureBox1 As System.Windows.Forms.PictureBox
	Friend WithEvents btnBack As System.Windows.Forms.Button
	Friend WithEvents btnEnter As System.Windows.Forms.Button
	Friend WithEvents lblCredit As System.Windows.Forms.Label
	Friend WithEvents txtCreditNo As System.Windows.Forms.TextBox
	Friend WithEvents txtPin As System.Windows.Forms.TextBox
	Friend WithEvents lblPin As System.Windows.Forms.Label
	Friend WithEvents btnOk As System.Windows.Forms.Button
	Friend WithEvents lblFailed As System.Windows.Forms.Label
	Friend WithEvents btnRetry As System.Windows.Forms.Button
	Friend WithEvents btnExit As System.Windows.Forms.Button
	Friend WithEvents lblCardOut As System.Windows.Forms.Label
	Friend WithEvents btnEject As System.Windows.Forms.Button
	Friend WithEvents lblFirst As System.Windows.Forms.Label
	Friend WithEvents lblHolderName As System.Windows.Forms.Label
	Friend WithEvents lblWant As System.Windows.Forms.Label
	Friend WithEvents PictureBox2 As System.Windows.Forms.PictureBox
	Friend WithEvents lblCurrentMoney As System.Windows.Forms.Label
	Friend WithEvents lblCurrentlyHave As System.Windows.Forms.Label
	Friend WithEvents lbldeposit As System.Windows.Forms.Label
	Friend WithEvents txtDeposit As System.Windows.Forms.TextBox
	Friend WithEvents btnDepoCom As System.Windows.Forms.Button
	Friend WithEvents btnWith As System.Windows.Forms.Button
	Friend WithEvents TextBox1 As System.Windows.Forms.TextBox
	<System.Diagnostics.DebuggerStepThrough()> Private Sub InitializeComponent()
		Dim resources As System.Resources.ResourceManager = New System.Resources.ResourceManager(GetType(Form1))
		Me.btnDeposit = New System.Windows.Forms.Button
		Me.btnWithdraw = New System.Windows.Forms.Button
		Me.btnBalance = New System.Windows.Forms.Button
		Me.btnBack = New System.Windows.Forms.Button
		Me.Panel1 = New System.Windows.Forms.Panel
		Me.btnWith = New System.Windows.Forms.Button
		Me.btnDepoCom = New System.Windows.Forms.Button
		Me.txtDeposit = New System.Windows.Forms.TextBox
		Me.lbldeposit = New System.Windows.Forms.Label
		Me.lblCurrentlyHave = New System.Windows.Forms.Label
		Me.lblCurrentMoney = New System.Windows.Forms.Label
		Me.PictureBox2 = New System.Windows.Forms.PictureBox
		Me.lblWant = New System.Windows.Forms.Label
		Me.lblHolderName = New System.Windows.Forms.Label
		Me.lblCardOut = New System.Windows.Forms.Label
		Me.btnExit = New System.Windows.Forms.Button
		Me.btnRetry = New System.Windows.Forms.Button
		Me.lblFailed = New System.Windows.Forms.Label
		Me.btnOk = New System.Windows.Forms.Button
		Me.txtPin = New System.Windows.Forms.TextBox
		Me.lblPin = New System.Windows.Forms.Label
		Me.txtCreditNo = New System.Windows.Forms.TextBox
		Me.lblCredit = New System.Windows.Forms.Label
		Me.lblFirst = New System.Windows.Forms.Label
		Me.PictureBox1 = New System.Windows.Forms.PictureBox
		Me.btnEnter = New System.Windows.Forms.Button
		Me.btnEject = New System.Windows.Forms.Button
		Me.TextBox1 = New System.Windows.Forms.TextBox
		Me.Panel1.SuspendLayout()
		Me.SuspendLayout()
		'
		'btnDeposit
		'
		Me.btnDeposit.Enabled = False
		Me.btnDeposit.Font = New System.Drawing.Font("Microsoft Sans Serif", 15.75!, System.Drawing.FontStyle.Bold, System.Drawing.GraphicsUnit.Point, CType(0, Byte))
		Me.btnDeposit.Location = New System.Drawing.Point(776, 48)
		Me.btnDeposit.Name = "btnDeposit"
		Me.btnDeposit.Size = New System.Drawing.Size(200, 272)
		Me.btnDeposit.TabIndex = 1
		Me.btnDeposit.Text = "Deposit Money"
		'
		'btnWithdraw
		'
		Me.btnWithdraw.Enabled = False
		Me.btnWithdraw.Font = New System.Drawing.Font("Microsoft Sans Serif", 15.75!, System.Drawing.FontStyle.Bold, System.Drawing.GraphicsUnit.Point, CType(0, Byte))
		Me.btnWithdraw.Location = New System.Drawing.Point(24, 48)
		Me.btnWithdraw.Name = "btnWithdraw"
		Me.btnWithdraw.Size = New System.Drawing.Size(200, 272)
		Me.btnWithdraw.TabIndex = 2
		Me.btnWithdraw.Text = "Withdraw Money"
		'
		'btnBalance
		'
		Me.btnBalance.Enabled = False
		Me.btnBalance.Font = New System.Drawing.Font("Microsoft Sans Serif", 15.75!, System.Drawing.FontStyle.Bold, System.Drawing.GraphicsUnit.Point, CType(0, Byte))
		Me.btnBalance.Location = New System.Drawing.Point(24, 320)
		Me.btnBalance.Name = "btnBalance"
		Me.btnBalance.Size = New System.Drawing.Size(200, 272)
		Me.btnBalance.TabIndex = 3
		Me.btnBalance.Text = "Check Accounts Balance"
		'
		'btnBack
		'
		Me.btnBack.Enabled = False
		Me.btnBack.Font = New System.Drawing.Font("Microsoft Sans Serif", 15.75!, System.Drawing.FontStyle.Bold, System.Drawing.GraphicsUnit.Point, CType(0, Byte))
		Me.btnBack.Location = New System.Drawing.Point(776, 320)
		Me.btnBack.Name = "btnBack"
		Me.btnBack.Size = New System.Drawing.Size(200, 272)
		Me.btnBack.TabIndex = 4
		Me.btnBack.Text = "Back"
		'
		'Panel1
		'
		Me.Panel1.BackColor = System.Drawing.SystemColors.ControlLightLight
		Me.Panel1.BorderStyle = System.Windows.Forms.BorderStyle.Fixed3D
		Me.Panel1.Controls.Add(Me.TextBox1)
		Me.Panel1.Controls.Add(Me.btnWith)
		Me.Panel1.Controls.Add(Me.btnDepoCom)
		Me.Panel1.Controls.Add(Me.txtDeposit)
		Me.Panel1.Controls.Add(Me.lbldeposit)
		Me.Panel1.Controls.Add(Me.lblCurrentlyHave)
		Me.Panel1.Controls.Add(Me.lblCurrentMoney)
		Me.Panel1.Controls.Add(Me.PictureBox2)
		Me.Panel1.Controls.Add(Me.lblWant)
		Me.Panel1.Controls.Add(Me.lblHolderName)
		Me.Panel1.Controls.Add(Me.lblCardOut)
		Me.Panel1.Controls.Add(Me.btnExit)
		Me.Panel1.Controls.Add(Me.btnRetry)
		Me.Panel1.Controls.Add(Me.lblFailed)
		Me.Panel1.Controls.Add(Me.btnOk)
		Me.Panel1.Controls.Add(Me.txtPin)
		Me.Panel1.Controls.Add(Me.lblPin)
		Me.Panel1.Controls.Add(Me.txtCreditNo)
		Me.Panel1.Controls.Add(Me.lblCredit)
		Me.Panel1.Controls.Add(Me.lblFirst)
		Me.Panel1.Controls.Add(Me.PictureBox1)
		Me.Panel1.Location = New System.Drawing.Point(240, 48)
		Me.Panel1.Name = "Panel1"
		Me.Panel1.Size = New System.Drawing.Size(520, 544)
		Me.Panel1.TabIndex = 5
		'
		'btnWith
		'
		Me.btnWith.BackColor = System.Drawing.SystemColors.Control
		Me.btnWith.Location = New System.Drawing.Point(224, 232)
		Me.btnWith.Name = "btnWith"
		Me.btnWith.Size = New System.Drawing.Size(64, 23)
		Me.btnWith.TabIndex = 19
		Me.btnWith.Text = "Withdraw"
		Me.btnWith.Visible = False
		'
		'btnDepoCom
		'
		Me.btnDepoCom.BackColor = System.Drawing.SystemColors.Control
		Me.btnDepoCom.Location = New System.Drawing.Point(226, 232)
		Me.btnDepoCom.Name = "btnDepoCom"
		Me.btnDepoCom.Size = New System.Drawing.Size(64, 23)
		Me.btnDepoCom.TabIndex = 18
		Me.btnDepoCom.Text = "Deposit"
		Me.btnDepoCom.Visible = False
		'
		'txtDeposit
		'
		Me.txtDeposit.BorderStyle = System.Windows.Forms.BorderStyle.None
		Me.txtDeposit.ForeColor = System.Drawing.Color.Red
		Me.txtDeposit.Location = New System.Drawing.Point(360, 149)
		Me.txtDeposit.Name = "txtDeposit"
		Me.txtDeposit.TabIndex = 17
		Me.txtDeposit.Text = ""
		Me.txtDeposit.Visible = False
		'
		'lbldeposit
		'
		Me.lbldeposit.ForeColor = System.Drawing.Color.Black
		Me.lbldeposit.Location = New System.Drawing.Point(96, 144)
		Me.lbldeposit.Name = "lbldeposit"
		Me.lbldeposit.Size = New System.Drawing.Size(256, 23)
		Me.lbldeposit.TabIndex = 16
		Me.lbldeposit.Text = "Enter The Amount You Want To Deposit --> Rs."
		Me.lbldeposit.TextAlign = System.Drawing.ContentAlignment.MiddleLeft
		Me.lbldeposit.Visible = False
		'
		'lblCurrentlyHave
		'
		Me.lblCurrentlyHave.ForeColor = System.Drawing.Color.Black
		Me.lblCurrentlyHave.Location = New System.Drawing.Point(96, 112)
		Me.lblCurrentlyHave.Name = "lblCurrentlyHave"
		Me.lblCurrentlyHave.Size = New System.Drawing.Size(256, 23)
		Me.lblCurrentlyHave.TabIndex = 15
		Me.lblCurrentlyHave.Text = "Currently You Have									--> Rs."
		Me.lblCurrentlyHave.TextAlign = System.Drawing.ContentAlignment.MiddleLeft
		Me.lblCurrentlyHave.Visible = False
		'
		'lblCurrentMoney
		'
		Me.lblCurrentMoney.ForeColor = System.Drawing.Color.Red
		Me.lblCurrentMoney.Location = New System.Drawing.Point(360, 112)
		Me.lblCurrentMoney.Name = "lblCurrentMoney"
		Me.lblCurrentMoney.Size = New System.Drawing.Size(160, 23)
		Me.lblCurrentMoney.TabIndex = 14
		Me.lblCurrentMoney.TextAlign = System.Drawing.ContentAlignment.MiddleLeft
		Me.lblCurrentMoney.Visible = False
		'
		'PictureBox2
		'
		Me.PictureBox2.Image = CType(resources.GetObject("PictureBox2.Image"), System.Drawing.Image)
		Me.PictureBox2.Location = New System.Drawing.Point(224, 408)
		Me.PictureBox2.Name = "PictureBox2"
		Me.PictureBox2.Size = New System.Drawing.Size(100, 96)
		Me.PictureBox2.TabIndex = 13
		Me.PictureBox2.TabStop = False
		'
		'lblWant
		'
		Me.lblWant.Location = New System.Drawing.Point(152, 56)
		Me.lblWant.Name = "lblWant"
		Me.lblWant.Size = New System.Drawing.Size(224, 23)
		Me.lblWant.TabIndex = 12
		Me.lblWant.Text = "What Do You Want To Do Please Select"
		Me.lblWant.TextAlign = System.Drawing.ContentAlignment.MiddleCenter
		Me.lblWant.Visible = False
		'
		'lblHolderName
		'
		Me.lblHolderName.Font = New System.Drawing.Font("Microsoft Sans Serif", 14.25!, System.Drawing.FontStyle.Bold, System.Drawing.GraphicsUnit.Point, CType(0, Byte))
		Me.lblHolderName.ForeColor = System.Drawing.Color.Navy
		Me.lblHolderName.Location = New System.Drawing.Point(112, 16)
		Me.lblHolderName.Name = "lblHolderName"
		Me.lblHolderName.Size = New System.Drawing.Size(296, 32)
		Me.lblHolderName.TabIndex = 11
		Me.lblHolderName.TextAlign = System.Drawing.ContentAlignment.MiddleCenter
		Me.lblHolderName.Visible = False
		'
		'lblCardOut
		'
		Me.lblCardOut.Font = New System.Drawing.Font("Times New Roman", 27.75!, System.Drawing.FontStyle.Bold, System.Drawing.GraphicsUnit.Point, CType(0, Byte))
		Me.lblCardOut.Location = New System.Drawing.Point(168, 152)
		Me.lblCardOut.Name = "lblCardOut"
		Me.lblCardOut.Size = New System.Drawing.Size(200, 168)
		Me.lblCardOut.TabIndex = 10
		Me.lblCardOut.Text = "Get Your Credit Card Out Thank You"
		Me.lblCardOut.TextAlign = System.Drawing.ContentAlignment.MiddleCenter
		Me.lblCardOut.Visible = False
		'
		'btnExit
		'
		Me.btnExit.BackColor = System.Drawing.SystemColors.Control
		Me.btnExit.Location = New System.Drawing.Point(224, 360)
		Me.btnExit.Name = "btnExit"
		Me.btnExit.Size = New System.Drawing.Size(64, 23)
		Me.btnExit.TabIndex = 9
		Me.btnExit.Text = "Exit"
		Me.btnExit.Visible = False
		'
		'btnRetry
		'
		Me.btnRetry.BackColor = System.Drawing.SystemColors.Control
		Me.btnRetry.Location = New System.Drawing.Point(224, 312)
		Me.btnRetry.Name = "btnRetry"
		Me.btnRetry.Size = New System.Drawing.Size(64, 23)
		Me.btnRetry.TabIndex = 8
		Me.btnRetry.Text = "Retry"
		Me.btnRetry.Visible = False
		'
		'lblFailed
		'
		Me.lblFailed.ForeColor = System.Drawing.Color.Red
		Me.lblFailed.Location = New System.Drawing.Point(123, 272)
		Me.lblFailed.Name = "lblFailed"
		Me.lblFailed.Size = New System.Drawing.Size(264, 23)
		Me.lblFailed.TabIndex = 7
		Me.lblFailed.Text = "Login Failed"
		Me.lblFailed.TextAlign = System.Drawing.ContentAlignment.MiddleCenter
		Me.lblFailed.Visible = False
		'
		'btnOk
		'
		Me.btnOk.BackColor = System.Drawing.SystemColors.Control
		Me.btnOk.Location = New System.Drawing.Point(224, 224)
		Me.btnOk.Name = "btnOk"
		Me.btnOk.Size = New System.Drawing.Size(64, 23)
		Me.btnOk.TabIndex = 6
		Me.btnOk.Text = "Ok"
		Me.btnOk.Visible = False
		'
		'txtPin
		'
		Me.txtPin.BorderStyle = System.Windows.Forms.BorderStyle.None
		Me.txtPin.Font = New System.Drawing.Font("Microsoft Sans Serif", 8.25!, System.Drawing.FontStyle.Bold, System.Drawing.GraphicsUnit.Point, CType(0, Byte))
		Me.txtPin.ForeColor = System.Drawing.SystemColors.HotTrack
		Me.txtPin.Location = New System.Drawing.Point(248, 164)
		Me.txtPin.Name = "txtPin"
		Me.txtPin.PasswordChar = Microsoft.VisualBasic.ChrW(42)
		Me.txtPin.Size = New System.Drawing.Size(200, 13)
		Me.txtPin.TabIndex = 5
		Me.txtPin.Text = ""
		Me.txtPin.Visible = False
		'
		'lblPin
		'
		Me.lblPin.Location = New System.Drawing.Point(96, 160)
		Me.lblPin.Name = "lblPin"
		Me.lblPin.Size = New System.Drawing.Size(112, 23)
		Me.lblPin.TabIndex = 4
		Me.lblPin.Text = "Enter Your PIN No"
		Me.lblPin.TextAlign = System.Drawing.ContentAlignment.MiddleLeft
		Me.lblPin.Visible = False
		'
		'txtCreditNo
		'
		Me.txtCreditNo.BorderStyle = System.Windows.Forms.BorderStyle.None
		Me.txtCreditNo.Font = New System.Drawing.Font("Microsoft Sans Serif", 8.25!, System.Drawing.FontStyle.Bold, System.Drawing.GraphicsUnit.Point, CType(0, Byte))
		Me.txtCreditNo.ForeColor = System.Drawing.SystemColors.HotTrack
		Me.txtCreditNo.Location = New System.Drawing.Point(248, 115)
		Me.txtCreditNo.Name = "txtCreditNo"
		Me.txtCreditNo.Size = New System.Drawing.Size(200, 13)
		Me.txtCreditNo.TabIndex = 3
		Me.txtCreditNo.Text = ""
		Me.txtCreditNo.Visible = False
		'
		'lblCredit
		'
		Me.lblCredit.Location = New System.Drawing.Point(96, 112)
		Me.lblCredit.Name = "lblCredit"
		Me.lblCredit.Size = New System.Drawing.Size(112, 23)
		Me.lblCredit.TabIndex = 2
		Me.lblCredit.Text = "Enter Credit Card No"
		Me.lblCredit.TextAlign = System.Drawing.ContentAlignment.MiddleLeft
		Me.lblCredit.Visible = False
		'
		'lblFirst
		'
		Me.lblFirst.Font = New System.Drawing.Font("Times New Roman", 27.75!, System.Drawing.FontStyle.Bold, System.Drawing.GraphicsUnit.Point, CType(0, Byte))
		Me.lblFirst.Location = New System.Drawing.Point(120, 272)
		Me.lblFirst.Name = "lblFirst"
		Me.lblFirst.Size = New System.Drawing.Size(296, 120)
		Me.lblFirst.TabIndex = 1
		Me.lblFirst.Text = "Please Enter Your Credit Card"
		Me.lblFirst.TextAlign = System.Drawing.ContentAlignment.MiddleCenter
		'
		'PictureBox1
		'
		Me.PictureBox1.Image = CType(resources.GetObject("PictureBox1.Image"), System.Drawing.Image)
		Me.PictureBox1.Location = New System.Drawing.Point(128, 56)
		Me.PictureBox1.Name = "PictureBox1"
		Me.PictureBox1.Size = New System.Drawing.Size(288, 176)
		Me.PictureBox1.TabIndex = 0
		Me.PictureBox1.TabStop = False
		'
		'btnEnter
		'
		Me.btnEnter.Location = New System.Drawing.Point(424, 600)
		Me.btnEnter.Name = "btnEnter"
		Me.btnEnter.Size = New System.Drawing.Size(176, 23)
		Me.btnEnter.TabIndex = 6
		Me.btnEnter.Text = "Press This After Enter The Card"
		'
		'btnEject
		'
		Me.btnEject.Location = New System.Drawing.Point(424, 600)
		Me.btnEject.Name = "btnEject"
		Me.btnEject.Size = New System.Drawing.Size(176, 23)
		Me.btnEject.TabIndex = 7
		Me.btnEject.Text = "Press This After Eject The Card"
		Me.btnEject.Visible = False
		'
		'TextBox1
		'
		Me.TextBox1.Location = New System.Drawing.Point(40, 48)
		Me.TextBox1.Name = "TextBox1"
		Me.TextBox1.TabIndex = 20
		Me.TextBox1.Text = "TextBox1"
		'
		'Form1
		'
		Me.AutoScaleBaseSize = New System.Drawing.Size(5, 13)
		Me.ClientSize = New System.Drawing.Size(984, 645)
		Me.Controls.Add(Me.btnEject)
		Me.Controls.Add(Me.btnEnter)
		Me.Controls.Add(Me.Panel1)
		Me.Controls.Add(Me.btnBack)
		Me.Controls.Add(Me.btnBalance)
		Me.Controls.Add(Me.btnWithdraw)
		Me.Controls.Add(Me.btnDeposit)
		Me.Name = "Form1"
		Me.StartPosition = System.Windows.Forms.FormStartPosition.CenterScreen
		Me.Text = "ATM Machine"
		Me.Panel1.ResumeLayout(False)
		Me.ResumeLayout(False)

	End Sub

#End Region
	Dim cn As New OleDbConnection
	Dim adpt As OleDbDataAdapter
	Dim ds As New DataSet
	Dim flag As Boolean = False
	Dim i As Integer
	Dim money As Integer
	Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
		cn = New OleDbConnection
		cn.ConnectionString = "Provider=Microsoft.jet.oledb.4.0;Data Source=d:\atm.mdb"
		adpt = New OleDbDataAdapter("select * from account", cn)
		ds = New DataSet("Atm1")
		adpt.Fill(ds, "account")


	End Sub

	Private Sub btnOk_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnOk.Click
	  
		Dim dt As DataTable
		dt = ds.Tables("account")

		'Dim i As Integer
		For i = 0 To dt.Rows.Count - 1
			If txtCreditNo.Text = dt.Rows(i)(0) And txtPin.Text = dt.Rows(i)(1) Then
				flag = True
				Exit For
			End If

		Next

		If flag = True Then
			txtCreditNo.Visible = False
			txtPin.Visible = False
			btnOk.Visible = False
			lblCredit.Visible = False
			lblPin.Visible = False
			btnBalance.Enabled = True
			btnDeposit.Enabled = True
			btnWithdraw.Enabled = True
			btnBack.Enabled = True
			Dim name As String = dt.Rows(i)(2)
			lblHolderName.Text = name
			lblHolderName.Visible = True
			lblWant.Visible = True

		Else
			btnOk.Enabled = False
			lblFailed.Visible = True
			txtCreditNo.Enabled = False
			txtPin.Enabled = False
			btnRetry.Visible = True
			btnExit.Visible = True

		End If

	End Sub


	Private Sub btnRetry_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnRetry.Click
		btnOk.Enabled = True
		btnExit.Visible = False
		txtCreditNo.Enabled = True
		txtCreditNo.Text = ""
		txtPin.Text = ""
		txtPin.Enabled = True
		btnRetry.Visible = False
		lblFailed.Visible = False
		txtCreditNo.Focus()
	End Sub
	Private Sub btnExit_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnExit.Click
		PictureBox2.Visible = True
		lblCardOut.Visible = True
		txtCreditNo.Visible = False
		txtPin.Visible = False
		lblCredit.Visible = False
		lblPin.Visible = False
		btnOk.Visible = False
		btnExit.Visible = False
		btnRetry.Visible = False
		lblFailed.Visible = False
		btnEject.Visible = True

	End Sub
	Private Sub btnDepoCom_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnDepoCom.Click
		Try
			cn = New OleDbConnection
			cn.ConnectionString = "Provider=Microsoft.jet.oledb.4.0;Data Source=d:\atm.mdb"
			adpt = New OleDbDataAdapter("UPDATE account SET money = 27 WHERE creditCardNo = '1'", cn)
			ds = New DataSet("Atm2")
			'adpt.Fill(ds, "account")
		 

			Dim ans As String
			Dim dep As Integer = 0


			dep = CInt(txtDeposit.Text())
			ans = MessageBox.Show("Are You Sure You Want To Deposit Rs." + CStr(dep), "Deposit Money", MessageBoxButtons.YesNo, MessageBoxIcon.Information)
			If ans = "6" Then

				Dim newMoney As Integer = 0
				newMoney = money + dep
				Dim dt As DataTable = ds.Tables("account")
				TextBox1.Text = CStr(newMoney)

				Dim dr As DataRow


				dr = ds.Tables("account").Rows(i)
				''MessageBox.Show("before" + CStr(dr("money")))



			   [color=#FF0000] dr.BeginEdit()


				dr(0) = txtCreditNo.Text

				dr(1) = txtPin.Text

				dr(2) = lblHolderName.Text

				dr(3) = CInt(TextBox1.Text)


				dr.EndEdit()[/color] 'this is the place tyhat not working


				MessageBox.Show(dr(3))

				Dim a As New OleDbCommandBuilder(adpt) 'this line will give us the permission to update,delete,insert the database
				adpt.Fill(ds.Tables("account"))
				'adpt.Update(ds.Tables("account")) 'error comes here


		End If
	 Catch ex As OleDbException

		End Try


	End Sub




	Private Sub btnDeposit_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnDeposit.Click

		Dim dt As DataTable

		dt = ds.Tables("account")
		money = dt.Rows(i)(3)
		btnBalance.Enabled = False
		btnWithdraw.Enabled = False


		btnDepoCom.Visible = True

		lblCurrentMoney.Visible = True
		lblCurrentlyHave.Visible = True
		lblWant.Text = "Account is Processing"
		lblCurrentMoney.Text = money
		lbldeposit.Visible = True
		txtDeposit.Visible = True
		txtDeposit.Focus()





	End Sub

	Private Sub btnWithdraw_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnWithdraw.Click
		Dim dt As DataTable

		dt = ds.Tables("account")
		money = dt.Rows(i)(3)
		btnBalance.Enabled = False
		btnWithdraw.Enabled = False

		btnDepoCom.Visible = False

		btnWith.Visible = True

		lblCurrentMoney.Visible = True
		lblCurrentlyHave.Visible = True
		lblWant.Text = "Account is Processing"
		lblCurrentMoney.Text = money
		lbldeposit.Visible = True
		lbldeposit.Text = "Enter The Amount You Want To Withdraw --> Rs."
		txtDeposit.Visible = True
		txtDeposit.Focus()

	End Sub

	Private Sub btnBalance_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnBalance.Click

	End Sub



	Private Sub btnEnter_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnEnter.Click

		PictureBox1.Visible = False
		PictureBox2.Visible = False
		lblFirst.Visible = False
		txtCreditNo.Visible = True
		txtCreditNo.Enabled = True
		lblCredit.Enabled = True
		lblPin.Enabled = True
		txtPin.Enabled = True
		txtCreditNo.Focus()
		lblCredit.Visible = True
		txtPin.Visible = True
		btnOk.Visible = True
		lblPin.Visible = True
		btnEnter.Enabled = False
		btnOk.Enabled = True
		txtCreditNo.Text = ""
		txtPin.Text = ""
		txtCreditNo.Focus()

	End Sub



	Private Sub btnEject_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnEject.Click
		PictureBox2.Visible = True
		lblCardOut.Visible = False
		btnEject.Visible = False
		btnEnter.Visible = True
		btnEnter.Enabled = True
		PictureBox1.Visible = True
		lblFirst.Visible = True
	End Sub

	Private Sub btnBack_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnBack.Click
		lblCurrentMoney.Visible = False
		lblCurrentlyHave.Visible = False

		lbldeposit.Visible = False
		txtDeposit.Visible = False
		PictureBox2.Visible = True
		lblCardOut.Visible = False
		btnEject.Visible = False
		btnEnter.Visible = True
		btnEnter.Enabled = True
		PictureBox1.Visible = True
		lblFirst.Visible = True
		lblHolderName.Visible = False
		lblWant.Visible = False
		btnBalance.Enabled = False
		btnDeposit.Enabled = False
		btnWithdraw.Enabled = False
		btnBack.Enabled = False

	End Sub

	Private Sub txtDeposit_KeyPress(ByVal sender As Object, ByVal e As System.Windows.Forms.KeyPressEventArgs) Handles txtDeposit.KeyPress
		If Char.IsDigit(e.KeyChar) = False Then	 'entering a character
			e.Handled = True 'if its a number only we can continue
		End If


	End Sub




	'Private Sub btnWith_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnWith.Click
	'	Dim ans As String
	'	Dim wit As Integer = 0


	'	wit = CInt(txtDeposit.Text())
	'	If money < 50000 And wit > 10000 Then
	'		MessageBox.Show("You should have over Rs.50000 to withdraw over Rs.10000 at once", "Try Again", MessageBoxButtons.OK, MessageBoxIcon.Exclamation)
	'		'Exit Sub
	'		txtDeposit.Focus()

	'		txtDeposit.SelectAll()
	'	End If
	'	ans = MessageBox.Show("Are You Sure You Want To Withdraw Rs." + CStr(wit), "Deposit Money", MessageBoxButtons.YesNo, MessageBoxIcon.Information)
	'	If ans = "6" Then

	'		Dim newMoney As Integer = 0
	'		newMoney = money - wit

	'		Dim dr As DataRow


	'		dr = ds.Tables("account").Rows(0)
	'		'MessageBox.Show("before" + CStr(dr("money")))



	'		dr.BeginEdit()
	'		dr(0) = txtCreditNo.Text

	'		dr(1) = txtPin.Text

	'		dr(2) = lblHolderName.Text

	'		dr(3) = newMoney

	'		dr.EndEdit()



	'		'MessageBox.Show("after" + CStr(dr("money")))

	'		Dim a As New OleDbCommandBuilder(adpt) 'this line will give us the permission to update,delete,insert the database


	'		adpt.Update(ds.Tables("account"))
	'	End If
	'End Sub
End Class



Is This A Good Question/Topic? 0
  • +

Replies To: Database Not Updating

#2 Jayman   User is offline

  • Student of Life
  • member icon

Reputation: 423
  • View blog
  • Posts: 9,532
  • Joined: 26-December 05

Re: Database Not Updating

Posted 18 November 2007 - 11:53 PM

Describe the problem that you are having and include any error messages that you are getting and we will try to help you.
Was This Post Helpful? 0
  • +
  • -

#3 baavgai   User is offline

  • Dreaming Coder
  • member icon


Reputation: 7507
  • View blog
  • Posts: 15,558
  • Joined: 16-October 07

Re: Database Not Updating

Posted 19 November 2007 - 06:56 AM

I would help if you offered the error, or a least gave less code. ;) Looks like you've been through the trail and error, comment it out phase, so I'll try to clarify.

Your are attempting to use a DataTable without structure.

I'm assuming insertion only here. I also took out the Try Catch. You'll want them back, buy only after you've tested.

Private Sub btnDepoCom_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnDepoCom.Click
	We're using a DataAdapter, ignore the next two lines
	' cn = New OleDbConnection
	' cn.ConnectionString = "Provider=Microsoft.jet.oledb.4.0;Data Source=d:\atm.mdb"
	' this has nothing to do with what you're attempting to do.  In any case, this only works for selects.
	' adpt = New OleDbDataAdapter("UPDATE account SET money = 27 WHERE creditCardNo = '1'", cn)
	' Here's the DataAdapter we'll use.  
	' we're loading in the structure of table account without any rows.
	Dim da As New OleDb.OleDbDataAdapter("select * from account where 0=1","Provider=Microsoft.jet.oledb.4.0;Data Source=d:\atm.mdb")
	' We're only working with one table, so no need to worry about a whole DataSet
	' ds = New DataSet("Atm2")
	Dim dt As New DataTable("account")
	' This is very important, we'll have zero rows in dt, but we'll also have the table structure.
	da.Fill(dt)

	Dim dep As Integer = CInt(txtDeposit.Text)
	Dim ans As String = MessageBox.Show("Are You Sure You Want To Deposit Rs." + CStr(dep), "Deposit Money", MessageBoxButtons.YesNo, MessageBoxIcon.Information)

	'Not sure if "6" makes sense, but I'll go with it.
	If ans <> "6" Then
		Return
	End If
	
	Dim newMoney As Integer = money + dep
	TextBox1.Text = CStr(newMoney)

	' We made one already
	' Dim dt As DataTable = ds.Tables("account")

	' This is an insert?  What's all this code
	' Dim dr As DataRow
	' dr = ds.Tables("account").Rows(i)
	' MessageBox.Show("before" + CStr(dr("money")))

	' This also important, the DataRow must belong to our working DataTable
	Dim dr As DataRow = dt.NewRow()
	' Not needed, we're inserting
	'dr.BeginEdit()
	dr(0) = txtCreditNo.Text
	dr(1) = txtPin.Text
	dr(2) = lblHolderName.Text
	dr(3) = newMoney

	'Not needed, we're inserting
	'dr.EndEdit()
	'This is needed, we've created a DataRow, we need to add it to the DataTable
	dt.Rows.Add(dr)

	'this line will give us the permission to update,delete,insert the database
	' That is a lie!
	' What this will do is allow us to add commands to our adapter.
	Dim cmdBuilder As New OleDbCommandBuilder(da)

	' You have to make sure your adapter has an insert command
	da.InsertCommand = cmdBuilder.GetInsertCommand()

	' Alright, fire!
	da.Update(dt)
End Sub



Hope this helps.
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1