4 Replies - 826 Views - Last Post: 19 May 2008 - 06:53 AM Rate Topic: -----

#1 a_a_s  Icon User is offline

  • D.I.C Head

Reputation: 0
  • View blog
  • Posts: 68
  • Joined: 20-February 08

date base update error

Posted 18 May 2008 - 09:13 AM

hi :)
i have the fellowing code for updating the database when its change in data grid
 While (r < DataGridView1.Rows.Count - 1)
			InsertCommand1.Parameters.Clear()
			InsertCommand1.CommandText = "UPDATE [Section] SET Capacity =" & DataGridView1.Rows(r).Cells(2).Value & "  WHERE SectionID = " & DataGridView1.Rows(r).Cells(1).Value 

			InsertCommand1.CommandType = CommandType.Text
			InsertCommand1 = InsertCommand1
			DataAdapter1.InsertCommand = InsertCommand1
			InsertCommand1.ExecuteNonQuery()
			DataAdapter1.Update(DataSet1, "Section")
			r += 1
		End While


it make the update but it give the fellowing error
Update requires a valid UpdateCommand when passed DataRow collection with modified rows.
when i but the fellowing command
Dim CmdB As New OleDb.OleDbCommandBuilder(DataAdapter1)
it give error in update statment

This post has been edited by a_a_s: 18 May 2008 - 09:28 AM


Is This A Good Question/Topic? 0
  • +

Replies To: date base update error

#2 a_a_s  Icon User is offline

  • D.I.C Head

Reputation: 0
  • View blog
  • Posts: 68
  • Joined: 20-February 08

Re: date base update error

Posted 18 May 2008 - 11:29 AM

please help
Was This Post Helpful? 0
  • +
  • -

#3 a_a_s  Icon User is offline

  • D.I.C Head

Reputation: 0
  • View blog
  • Posts: 68
  • Joined: 20-February 08

Re: date base update error

Posted 19 May 2008 - 01:48 AM

please i need help
Was This Post Helpful? 0
  • +
  • -

#4 nofear217  Icon User is offline

  • D.I.C Regular
  • member icon

Reputation: 14
  • View blog
  • Posts: 323
  • Joined: 08-November 07

Re: date base update error

Posted 19 May 2008 - 06:22 AM

A problem I see is in
InsertCommand1.CommandText = "UPDATE [Section] SET Capacity =" & DataGridView1.Rows(r).Cells(2).Value & "  WHERE SectionID = " & DataGridView1.Rows(r).Cells(1).Value


There needs to be ' wrapped around the fields that you want to insert...like this
InsertCommand1.CommandText = "UPDATE [Section] SET Capacity ='" & DataGridView1.Rows(r).Cells(2).Value & "'  WHERE SectionID = '" & DataGridView1.Rows(r).Cells(1).Value & "'"


That's just standard SQL, also if you are planning to do this in anything for production, then I would recommend parameterizing it.

This post has been edited by nofear217: 19 May 2008 - 06:23 AM

Was This Post Helpful? 0
  • +
  • -

#5 a_a_s  Icon User is offline

  • D.I.C Head

Reputation: 0
  • View blog
  • Posts: 68
  • Joined: 20-February 08

Re: date base update error

Posted 19 May 2008 - 06:53 AM

View Postnofear217, on 19 May, 2008 - 06:22 AM, said:

A problem I see is in
InsertCommand1.CommandText = "UPDATE [Section] SET Capacity =" & DataGridView1.Rows(r).Cells(2).Value & "  WHERE SectionID = " & DataGridView1.Rows(r).Cells(1).Value


There needs to be ' wrapped around the fields that you want to insert...like this
InsertCommand1.CommandText = "UPDATE [Section] SET Capacity ='" & DataGridView1.Rows(r).Cells(2).Value & "'  WHERE SectionID = '" & DataGridView1.Rows(r).Cells(1).Value & "'"


That's just standard SQL, also if you are planning to do this in anything for production, then I would recommend parameterizing it.



but the parameter are number
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1