Updating Access Database

Value of type 'Boolean' cannot be converted to 'System.Dat

Page 1 of 1

4 Replies - 2171 Views - Last Post: 13 September 2009 - 10:31 PM Rate Topic: -----

#1 hmssiri  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 6
  • Joined: 05-September 09

Updating Access Database

Post icon  Posted 13 September 2009 - 02:32 AM

If I am to update table 'Province' in databse get "Value of type 'Boolean' cannot be converted to 'System.Data.DataRow"

Code is here. pl.. let me know any mistake that I have done.

Is there any other easy method to update table in Access Database?

Thanks
hmssiri

Imports System.Data.OleDb
Public Class Form4
	Inherits System.Windows.Forms.Form
	Dim myadapter As New OleDbDataAdapter
	Dim mydataset As New DataSet
	Dim olecon As New OleDb.OleDbConnection("Provider=Microsoft.Jet.OLEDB.4.0;Data Source=D:\eUnion\eUnion.mdb")
	Public mybmb As BindingManagerBase
	Dim myrow As DataRow

	Private Sub Form4_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
		olecon.Open()
		myadapter.SelectCommand = New OleDbCommand("select * from province", olecon)
		myadapter.Fill(mydataset, "province")
		mybmb = BindingContext(mydataset, "province")
		Me.BindingContext(mydataset, "province").Position = 0
		Showrecords()
	End Sub
	Sub Showrecords()
		Dim oRaw As DataRow
		Dim OTable As DataTable
		OTable = mydataset.Tables("province")
		oRaw = OTable.Rows(mybmb.Position)
		TextBox1.Text = oRaw("province")
		TextBox2.Text = oRaw("PDiscript")
	End Sub


	Private Sub BtnUpdate_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles BtnUpdate.Click
		If mydataset.HasChanges(DataRowState.Added) Then
			Dim myAddDataset As New DataSet()
			AddPrTable(myAddDataset)
			MessageBox.Show("Added to Database Successfull")
		Else
			MessageBox.Show("No Record Added...")
		End If
	End Sub
	Sub AddPrTable(ByVal myAddDataset As DataSet)
		Try
			Dim myrow As DataRow
			Dim intRowsAffected As Integer
			For Each myrow In myAddDataset.Tables("province").Rows
				Dim cmdCommand As New OleDb.OleDbCommand()
				insertAddParam(cmdCommand, myrow)
				intRowsAffected = ExecuteStoredProcedure("spAddRecord", cmdCommand)
			Next
			mydataset.AcceptChanges()

		Catch oEx As Exception
			MessageBox.Show("The following Error occured:" & oEx.Message)
		End Try
	End Sub

	Sub insertAddParam(ByRef cmdcommand As OleDb.OleDbCommand, ByVal myrow As DataRow)
		Dim oleparm As New OleDb.OleDbParameter()
		oleparm = cmdcommand.Parameters.Add("@province", OleDbType.Char, 2)
		oleparm.Value = myrow("province")
		oleparm = cmdcommand.Parameters.Add("@PDiscript", OleDbType.Char, 25)
		oleparm.Value = myrow("PDiscript")
	End Sub
	Function ExecuteStoredProcedure(ByVal Strspname As String, ByVal cmdcommand As OleDbCommand) As Integer
		Dim intRowsAffected As Integer
		olecon.Open()
		Dim cmdparms As OleDb.OleDbCommand = cmdcommand
		cmdparms.Connection = olecon
		cmdparms.CommandType = CommandType.StoredProcedure
		cmdparms.CommandText = Strspname
		intRowsAffected = cmdparms.ExecuteNonQuery
		olecon.Close()
	End Function


	Private Sub BtnAdd_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles BtnAdd.Click
		'Dim myrow As DataRow
		myrow = mydataset.Tables("province").NewRow

		myrow = ("province") = TextBox1.Text
		myrow = ("pDiscript") = TextBox2.Text
		mydataset.Tables("province").Rows.Add(myrow)
		mybmb.Position = mybmb.Count - 1
		Showrecords()
	End Sub
End Class



Is This A Good Question/Topic? 0
  • +

Replies To: Updating Access Database

#2 modi123_1  Icon User is online

  • Suitor #2
  • member icon



Reputation: 8364
  • View blog
  • Posts: 31,076
  • Joined: 12-June 08

Re: Updating Access Database

Posted 13 September 2009 - 08:47 AM

Where you are getting this error? As in what line did you debug to that threw this? My guess is you forgot to cast a cell from a row as a bool.
Was This Post Helpful? 0
  • +
  • -

#5 aks29921  Icon User is offline

  • D.I.C Head
  • member icon

Reputation: 84
  • View blog
  • Posts: 230
  • Joined: 24-August 09

Re: Updating Access Database

Posted 13 September 2009 - 11:00 AM

i would prefer to simply use the update query instead...
UPDATE <tablename> SET <columnname1>=<value1>,<columnname2>=<value2>..... WHERE <condition(if any)>

1 more thing, if u still get ny similar error as to what u hv got here, kindly point out the line on which the error is occuring.. that way the problem can be detected much easily and quickly..
Was This Post Helpful? 1
  • +
  • -

#6 hmssiri  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 6
  • Joined: 05-September 09

Re: Updating Access Database

Posted 13 September 2009 - 08:11 PM

View Postmodi123_1, on 13 Sep, 2009 - 07:47 AM, said:

Where you are getting this error? As in what line did you debug to that threw this? My guess is you forgot to cast a cell from a row as a bool.


Thanks

This is the error. I am not familiar with this blog. Sorry for inconvenieance caused.

hmssiri

Error 1 Value of type 'Boolean' cannot be converted to 'System.Data.DataRow'.
line no. 76

Error2 Value of type 'Boolean' cannot be converted to 'System.Data.DataRow'.
line no. 77
Was This Post Helpful? 0
  • +
  • -

#7 modi123_1  Icon User is online

  • Suitor #2
  • member icon



Reputation: 8364
  • View blog
  • Posts: 31,076
  • Joined: 12-June 08

Re: Updating Access Database

Posted 13 September 2009 - 10:31 PM

View Posthmssiri, on 13 Sep, 2009 - 09:11 PM, said:

View Postmodi123_1, on 13 Sep, 2009 - 07:47 AM, said:

Where you are getting this error? As in what line did you debug to that threw this? My guess is you forgot to cast a cell from a row as a bool.


Thanks

This is the error. I am not familiar with this blog. Sorry for inconvenieance caused.

hmssiri

Error 1 Value of type 'Boolean' cannot be converted to 'System.Data.DataRow'.
line no. 76

Error2 Value of type 'Boolean' cannot be converted to 'System.Data.DataRow'.
line no. 77


What are the lines of code at line 76 and 77?
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1