how to delete selected rowin a data gridview

Hi, how do I permanently delete selected row in datagridview as well a

Page 1 of 1

3 Replies - 15679 Views - Last Post: 13 September 2009 - 01:03 AM Rate Topic: -----

#1 rocks_lp  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 16
  • Joined: 24-December 08

how to delete selected rowin a data gridview

Posted 25 December 2008 - 11:42 AM

Hi, how do I permanently delete selected row in datagridview as well as permanently deleting it in my .mdb file?.

what i want to do is. after i select a row in datagridwindow and then, when i click the delete button i want the data to be deleted from my datagridwindow and also from the database.

i am using vb.net 2005

plz plz plzzzzzzzzzzzzzzzzz help me!!!!!!!!!!!
SUICIDAL SITUATION

This post has been edited by rocks_lp: 25 December 2008 - 11:43 AM


Is This A Good Question/Topic? 0
  • +

Replies To: how to delete selected rowin a data gridview

#2 vks.gautam1  Icon User is offline

  • D.I.C Regular

Reputation: 17
  • View blog
  • Posts: 317
  • Joined: 21-March 08

Re: how to delete selected rowin a data gridview

Posted 25 December 2008 - 11:26 PM

I fu have tried any code pls provide here

use value property of DataGridview & then serach that value & delete that data from Your Database.
Was This Post Helpful? 0
  • +
  • -

#3 vks.gautam1  Icon User is offline

  • D.I.C Regular

Reputation: 17
  • View blog
  • Posts: 317
  • Joined: 21-March 08

Re: how to delete selected rowin a data gridview

Posted 26 December 2008 - 02:33 AM

Try This. Pls post your codes from now onwards for your benefit.

Private Sub btnDelete_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnDelete.Click
		Try
			If Not DataGridView1.CurrentRow.IsNewRow Then
'Query string
				q = "delete * from Table Name where Column Name='" & DataGridView1.CurrentRow.Cells(0).Value & "'"
			 
'oledb connection	
				cn = New OleDbConnection("microsoft.jet.oledb.4.0;data source=File Path";)
				cn.Open()
'command button
				cmd = New OleDbCommand(q, cn)
				cmd.ExecuteNonQuery()
				DataGridView1.Rows.Remove(DataGridView1.CurrentRow)
				MessageBox.Show("Record Deleted")
			End If
		Catch ex As Exception
			MessageBox.Show(ex.Message)

		End Try
		
	End Sub



This post has been edited by vks.gautam1: 26 December 2008 - 03:01 AM

Was This Post Helpful? 0
  • +
  • -

#4 epit89  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 1
  • Joined: 08-September 09

Re: how to delete selected rowin a data gridview

Posted 13 September 2009 - 01:03 AM

hi!! anyone can help me?? i hav problem. here is my code
Private Sub Button4_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button4.Click

		Try
			If Not DataGridView1.CurrentRow.IsNewRow Then
				'Query string

				'oledb connection	
				cn.ConnectionString = ("Data Source=AFIFF-PC\SQLEXPRESS;Initial Catalog=ULS;Integrated Security=True")
				cn.Open()
				'command button
				cm = New SqlCommand("delete * from Register where Table Name ='" & DataGridView1.CurrentRow.Cells(0).Value & "'", cn)
				cm.ExecuteNonQuery()
				DataGridView1.Rows.Remove(DataGridView1.CurrentRow)
				MessageBox.Show("Record Deleted")
			End If
		Catch ex As Exception
			MessageBox.Show(ex.Message)

		End Try

		cn.Close()

	End Sub



Register is my table name and i dont know what to put at column name because i have 5 column.

thx..
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1