Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

delete

Status
Not open for further replies.

adamdavies

Programmer
May 21, 2003
20
AU

i want to select a row in a gridbox and delete that row from the database

example from book doesnt seem to work


Public Sub DeleteRecord(ByVal sender As Object, ByVal e As
DataGridCommandEventArgs)

//what code do i need to delete the row

End Sub

thanks
adam
 
Private Sub DataGrid1_DeleteCommand(ByVal source As Object, ByVal e As System.Web.UI.WebControls.DataGridCommandEventArgs) Handles DataGrid1.DeleteCommand


Dim index As Integer
index = e.Item.ItemIndex


YourDataSet.YourDatabase.Rows(index).Delete()
YourDataAdapter.Update(YourDataSet)
YourDataAdapter.Fill(YourDataSet)

YourDataGrid.DataBind()

End Sub
 
thanks alot for the help.

im getting error
Input string was not in a correct format.

Dim QuickRefID As Int32 = Convert.ToInt32(e.Item.Cells(0).Text)

below is my code:

Private strconnection As String = ("Provider=Microsoft.Jet.OLEDB.4.0;data source=" & Server.MapPath("Intranet.mdb"))
'ConfigurationSettings.AppSettings("Intranet")
Private strSQLSelect As String = "SELECT QuickRefID,Company, FName, SName, Phone, Email, Notes, Employee, CDate FROM QuickQuery"
Private QueryTableName As String = "QueryTable"
Private objconnection As OleDbConnection


Private Sub Page_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
If Not Page.IsPostBack Then
loadgrid()
End If
End Sub

'///////////////////////////////////////////////////////////////////
Private Sub loadgrid()
connect()
Dim adapter As New OleDbDataAdapter(strSQLSelect, objconnection)
Dim ds As New DataSet()
adapter.Fill(ds, QueryTableName)
disconnect()

With dgusers
.DataSource = ds.Tables(QueryTableName)
.DataBind()
End With

End Sub
'//////
Private Sub connect()
If objconnection Is Nothing Then
objconnection = New OleDbConnection(strconnection)

End If
If objconnection.State = ConnectionState.Closed Then
objconnection.Open()
End If
End Sub
'//////
Private Sub disconnect()
objconnection.Close()
End Sub
'//////

Public Sub DeleteRecord(ByVal sender As Object, ByVal e As DataGridCommandEventArgs)
Dim ds As New DataSet() 'added, not from book
Dim QuickRefID As Int32 = Convert.ToInt32(e.Item.Cells(0).Text)
dgusers.EditItemIndex = -1
DeleteQuery(QuickRefID)

dgusers.DataSource = ds.tables(QueryTableName)
dgusers.DataBind()

End Sub
'///////
Private Sub DeleteQuery(ByVal QuickRefID As Long)
connect()
Dim adapter As New OleDbDataAdapter(strSQLSelect, objconnection)
Dim ds As New DataSet()
adapter.Fill(ds, QueryTableName)
disconnect()
Dim tbl As DataTable = ds.Tables(QueryTableName)
tbl.PrimaryKey = New DataColumn() _
{ _
tbl.Columns("QuickRefID") _
}
Dim ROW As DataRow = tbl.Rows.Find(QuickRefID)
ROW.Delete()
Dim cb As New OleDbCommandBuilder(adapter)
connect()
adapter.Update(ds, QueryTableName)
disconnect()
End Sub
 
im still getting prob, can anyone help

thanks ads
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top