4 Replies - 5334 Views - Last Post: 19 August 2009 - 07:26 PM Rate Topic: -----

#1 xoops  Icon User is offline

  • D.I.C Head

Reputation: 0
  • View blog
  • Posts: 81
  • Joined: 06-August 09

how delete the current record datagridview using adodb in vb.net

Posted 18 August 2009 - 11:48 PM

how to delete the current record datagridview using adodb in vb.net...

this is my code:

Private Sub cmdDelete_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles cmdDelete.Click
			 adrCURR.Delete(ADODB.AffectEnum.adAffectCurrent)
end sub



the code is working but not the current rows is deleting, but the first record is deleting...

Please help me...


I do not know what should be..


Thanx's

Is This A Good Question/Topic? 0
  • +

Replies To: how delete the current record datagridview using adodb in vb.net

#2 DataPriest  Icon User is offline

  • D.I.C Head

Reputation: 20
  • View blog
  • Posts: 57
  • Joined: 29-April 09

Re: how delete the current record datagridview using adodb in vb.net

Posted 19 August 2009 - 01:06 AM

Hi xoops

It looks like the cursor will be pointing on the first record each time you execute the delete event.

For you to delete the desired record, you have to move the cursor to that particular record before executing the delete event. You can do so by using the Move method:

adrCURR.Move (X, [Y])


This command will move the cursor X positions after record Y. X is the number of records you want the cursor to move and Y is the starting record. Please note, the Y parameter is optional.

Depending on how you structured your database, you can use an SQL statement to accomplish this.

"SELECT * FROM tablename WHERE fieldname = '" & recordID & "'"


Then execute your delete event code.

Better yet, you can replace SELECT with DELETE and replace the code in the delete event.

This post has been edited by DataPriest: 19 August 2009 - 01:18 AM

Was This Post Helpful? 0
  • +
  • -

#3 xoops  Icon User is offline

  • D.I.C Head

Reputation: 0
  • View blog
  • Posts: 81
  • Joined: 06-August 09

Re: how delete the current record datagridview using adodb in vb.net

Posted 19 August 2009 - 01:13 AM

i don't understand what you mean.. I'm beginner. :) please give sample code..
Thanx's
Was This Post Helpful? 0
  • +
  • -

#4 DataPriest  Icon User is offline

  • D.I.C Head

Reputation: 20
  • View blog
  • Posts: 57
  • Joined: 29-April 09

Re: how delete the current record datagridview using adodb in vb.net

Posted 19 August 2009 - 01:58 AM

Try this and of course you have to substitute some of the elements with ones suiting your scenario:

		Try
			Dim cn As New ADODB.Connection
			Dim Cmd As ADODB.Command
			Dim rs As New ADODB.Recordset
			Dim SQLCommand As String = "SELECT * FROM Users WHERE UserID = '" & sUserIDToDelete & "'"


			cn.Open(sDataSource, sUserID, sPassword)
			Cmd.ActiveConnection = cn
			Cmd.CommandText = SQLCommand
			rs.Open(Cmd, cn)
			rs.Close()
		Catch ex As Exception
			MessageBox.Show(ex.Message)
		End Try


Please note, sUserIDToDelete, sDataSource, sUserID & sPassword are string variable which need to be declared and must have values.

Hope this works. :)

This post has been edited by DataPriest: 19 August 2009 - 02:03 AM

Was This Post Helpful? 0
  • +
  • -

#5 xoops  Icon User is offline

  • D.I.C Head

Reputation: 0
  • View blog
  • Posts: 81
  • Joined: 06-August 09

Re: how delete the current record datagridview using adodb in vb.net

Posted 19 August 2009 - 07:26 PM

Thank you for your help... Mr. DataPriest...

This is my code...

Private Sub cmdDelete_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles cmdDelete.Click

		If tdgShow.Rows.Count = 0 Then
			MsgBox("Table is empty", vbExclamation, "Delete Data")
		Else
			If MsgBox("Are you sure delete this record ?", vbExclamation + vbYesNo, "Delete Data") = vbYes Then

				Try
					Dim baris As Integer
					baris = tdgShow.CurrentRow.Index()

					cSQL = "DELETE FROM MS_UMR WHERE TAHUN = '" & Trim(tdgShow.Item(0, baris).Value) & "'"

					adcLEDGER.Execute(cSQL)
				Catch ex As SqlException
					MsgBox(ex.Message)
				End Try
			End If

		End If
end sub



The code is working.. Now i can continue my work... Thanx's again.

I hope you not boring with me. :D

This post has been edited by xoops: 19 August 2009 - 07:26 PM

Was This Post Helpful? 0
  • +
  • -

Page 1 of 1