About Syed Adeel Rizvi Expertise I can answers questions regarding web based and desktop based programming in VB.Net. Which can include XML, Custom Controls + Computer Hardware and Windows Turboshooting...etc.
More Skills :
1 . PHP - > All Type Of CMS e.g. (Joomla,Drupul,PHPNuke...etc)
2 . ASP
3 . ASP.Net
4 . CMS
5 . MySql
6 . SQl Server 2000 & 2005
7 . Ms Access
8 . Web Designing
9 . Networking Turboshooting
10 . Windows Turboshooting
11 . Hardware Turboshooting
All Type Of Work Related To IT
I also Do Work as a Freelance as Application & Web Developer & Designer
Experience i have 3 years work experience in software house and 4 years work experience for computer hardware and Networking..
Expert: Syed Adeel Rizvi Date: 4/11/2008 Subject: Sorry another query!
Question Hi,
I have created a DataGrid and sucessfully managed to program it (manually) so that it displays records, I can then alter and update these records but I have yet to work out a sucessful way of deleting a record.
I can create a query in the access database that when it runs it deletes the row but I can not recreate this in the program.
Dim Con As New System.Data.OleDb.OleDbConnection
Dim ds As New Data.DataSet
Dim da As Data.OleDb.OleDbDataAdapter
Dim sqcon As Data.SqlClient.SqlConnection
Dim sqcom As Data.SqlClient.SqlCommand
Dim sqlSoftwareInstallation As String
Dim sqlDelete As String
Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs)
End Sub
Sub PopulateDataGrid()
GetData()
BindGV()
End Sub
Sub GetData()
Con.ConnectionString = "PROVIDER=Microsoft.Jet.OLEDB.4.0;Data Source = C:\Project\database\Backend.mdb"
'Opens the connection to the database
Con.Open()
'This is table spercific
sqlSoftwareInstallation = "SELECT * FROM tbl_SoftwareInstallation WHERE Tag = '" + Request("Tag") + "';"
da = New Data.OleDb.OleDbDataAdapter(sqlSoftwareInstallation, Con)
da.Fill(ds, "AmendInstallation")
'Closes the connection to the database
Con.Close()
End Sub
Private Sub BindGV()
Try
'Assigning Dataset to GridView
GridView1.DataSource = ds
'Bind Gridview
GridView1.DataBind()
Catch ex As Exception
End Try
End Sub
Protected Sub GridView1_RowEditing(ByVal sender As Object, ByVal e As System.Web.UI.WebControls.GridViewEditEventArgs) Handles GridView1.RowEditing
GridView1.EditIndex = e.NewEditIndex
PopulateDataGrid()
End Sub
Protected Sub GridView1_RowUpdating(ByVal sender As Object, ByVal e As System.Web.UI.WebControls.GridViewUpdateEventArgs) Handles GridView1.RowUpdating
' Get the new values from the GridView controls
Dim i As Integer = GridView1.Rows(e.RowIndex).DataItemIndex
Label1.Text = CType(GridView1.Rows(e.RowIndex).Cells(2).Controls(0), TextBox).Text
Dim InstallationID As String = CType(GridView1.Rows(e.RowIndex).Cells(2).Controls(0), TextBox).Text
Dim Tag As String = CType(GridView1.Rows(e.RowIndex).Cells(3).Controls(0), TextBox).Text
Dim SoftwareID As String = CType(GridView1.Rows(e.RowIndex).Cells(4).Controls(0), TextBox).Text
Dim InstallationDate As String = CType(GridView1.Rows(e.RowIndex).Cells(5).Controls(0), TextBox).Text
Con.ConnectionString = "PROVIDER=Microsoft.Jet.OLEDB.4.0;Data Source = C:\Project\database\Backend.mdb"
'Opens the connection to the database
Con.Open()
'This is table spercific
sqlSoftwareInstallation = "SELECT * FROM tbl_SoftwareInstallation WHERE Tag = '" + Request("Tag") + "';"
da = New Data.OleDb.OleDbDataAdapter(sqlSoftwareInstallation, Con)
da.Fill(ds, "AmendInstallation2")
Dim cb As New Data.OleDb.OleDbCommandBuilder(da)
ds.Tables("AmendInstallation2").Rows(i).Item(0) = InstallationID
ds.Tables("AmendInstallation2").Rows(i).Item(1) = Tag
ds.Tables("AmendInstallation2").Rows(i).Item(2) = SoftwareID
ds.Tables("AmendInstallation2").Rows(i).Item(3) = InstallationDate
End Sub
Protected Sub GridView1_RowCancelling(ByVal sender As Object, ByVal e As System.Web.UI.WebControls.GridViewCancelEditEventArgs) Handles GridView1.RowCancelingEdit
GridView1.EditIndex = -1
PopulateDataGrid()
End Sub
Protected Sub GridView1_RowDeleting(ByVal sender As Object, ByVal e As System.Web.UI.WebControls.GridViewDeleteEventArgs) Handles GridView1.RowDeleting
PopulateDataGrid()
Dim i As Integer = GridView1.Rows(e.RowIndex).DataItemIndex
Dim InstallationID As String = (GridView1.Rows(i).Cells(2).Text)
Label1.Text = InstallationID
Con.ConnectionString = "PROVIDER=Microsoft.Jet.OLEDB.4.0;Data Source = C:\Project\database\Backend.mdb"
'Opens the connection to the database
Con.Open()
sqlDelete = "DELETE tbl_SoftwareInstallation.* FROM tbl_SoftwareInstallation WHERE InstallationID = " + InstallationID + ";"
da = New Data.OleDb.OleDbDataAdapter(sqlDelete, Con)
sqlSoftwareInstallation = "SELECT * FROM tbl_SoftwareInstallation WHERE Tag = '" + Request("Tag") + "';"
da = New Data.OleDb.OleDbDataAdapter(sqlSoftwareInstallation, Con)
da.Fill(ds, "AmendInstallation")
This is the part that im not sure how to do:
Protected Sub GridView1_RowDeleting(ByVal sender As Object, ByVal e As System.Web.UI.WebControls.GridViewDeleteEventArgs) Handles GridView1.RowDeleting
PopulateDataGrid()
Dim i As Integer = GridView1.Rows(e.RowIndex).DataItemIndex
Dim InstallationID As String = (GridView1.Rows(i).Cells(2).Text)
Label1.Text = InstallationID
Con.ConnectionString = "PROVIDER=Microsoft.Jet.OLEDB.4.0;Data Source = C:\Project\database\Backend.mdb"
'Opens the connection to the database
Con.Open()
sqlDelete = "DELETE tbl_SoftwareInstallation.* FROM tbl_SoftwareInstallation WHERE InstallationID = " + InstallationID + ";"
da = New Data.OleDb.OleDbDataAdapter(sqlDelete, Con)
sqlSoftwareInstallation = "SELECT * FROM tbl_SoftwareInstallation WHERE Tag = '" + Request("Tag") + "';"
da = New Data.OleDb.OleDbDataAdapter(sqlSoftwareInstallation, Con)
da.Fill(ds, "AmendInstallation")
Con.Close()
GridView1.EditIndex = -1
End Sub
Any surgestions? All I want to do is delete the row based on that query.
Many Thanks
Ben
Answer Hello,
this is not correct :
sqlDelete = "DELETE tbl_SoftwareInstallation.* FROM tbl_SoftwareInstallation WHERE InstallationID = " + InstallationID + ";"
this is correct :
sqlDelete = "DELETE From tbl_SoftwareInstallation WHERE InstallationID = " & InstallationID & ";"