473,549 Members | 2,346 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

delete record from ms access database

Phi
Hi,

I hope somebody could help me with this problem.

I would like to make a form to add and delete records from my ms access
database. I've found most of the codes from the internet and adjusted
some part of it. Anyhow, inserting records to the database seems to work
fine, but deleting the records is not working as I want to and I just
can't see what's causing the problem.

Please, feel free to respond. Any comments/suggestion is welcome.

Thanks in advance for you help.

Kind regards,

Phi

code
========

<%@ Import Namespace="Syst em.Data" %>
<%@ Page Language = "vb" debug="true"%>
<%@ Import Namespace = "System.Data.Ol eDb" %>

<script language="vb" runat="server">
Private Sub Page_Load(sende r As Object, e As EventArgs)
If Not Page.IsPostBack Then
viewstate("sort Field") = "test_id"
viewstate("sort Direction") = "DESC"
testBindGrid()
End If
End Sub
sub onupdate(obj as object, e as eventargs)
dim StrSQl as string = "Insert into tbltest (test, test2 ) values
('" & tbx_test.text & "', '" & tbx_test2.text & "')"
ExecuteStatemen t(StrSQL)

testBindGrid()
End Sub

sub Delete_Record_t blTest(obj as object, e as DataGridCommand Eventargs)
dim strSQL as string = "delete from tbltest where test_id = " &
e.Item.ItemInde x
lbl_delete_strS QL.text = strsql
end sub

function ExecuteStatemen t(StrSQL)
Dim strConn As String = "Provider=Micro soft.Jet.Oledb. 4.0;" & "Data
Source=" & Server.MapPath( "/data/test.mdb") & ";"
Dim MyConn As New OleDBConnection (strConn)
dim objCmd as new OleDbCommand(St rSQL, MyConn)
objCmd.Connecti on.Open()
objCmd.ExeCuteN onQuery()

''close the connection to get the affected record in the table
objCmd.Connecti on.Close()
end function

Private Sub testBindGrid()
Dim strConn As string = "Provider=Micro soft.Jet.Oledb. 4.0;" & "Data
Source=" & Server.MapPath( "/data/test.mdb") & ";"
Dim MySQL As string = "SELECT tbltest.test_id , tbltest.test,
tbltest.test2 FROM tbltest ORDER BY " _
& viewstate("sort Field").ToStrin g() & " " & viewstate
("sortDirection ").ToString ()
Dim MyConn As New OleDBConnection (strConn)
Dim ds As DataSet = New DataSet()
Dim Cmd As New OleDBDataAdapte r(MySQL,MyConn)
Cmd.Fill(ds,"te st")

testDataGrid.Da taSource = ds
testDataGrid.Da tabind()

End Sub
Private Sub testPageGrid(By Val source As Object, ByVal e As
DataGridPageCha ngedEventArgs)
testDataGrid.Cu rrentPageIndex = e.NewPageIndex
testBindGrid()
End Sub

Private Sub testSortGrid(By Val source As Object, ByVal e As
DataGridSortCom mandEventArgs)
If e.SortExpressio n.ToString() = viewstate("sort Field").ToStrin g() Then
Select Case viewstate("sort Direction").ToS tring()
Case "ASC"
viewstate("sort Direction") = "DESC"
Case "DESC"
viewstate("sort Direction") = "ASC"
End Select
Else
viewstate("sort Field") = e.SortExpressio n
viewstate("sort Direction") = "DESC"
End If
testBindGrid()
End Sub

</script>
<html>

<body>

<form runat="server" method="post">
Insert Records in to the table Test<br><br>

<table>
<tr>
<td>test:</td>

<td><asp:textbo x id="tbx_test"
runat="server"/></td>
</tr>

<tr>
<td>test2:</td>

<td><asp:textbo x id="tbx_test2"
runat="server"/><br></td>
</tr>

<tr>
<td>

</td>

<td>

<asp:button id="button1" OnClick=
"onupdate" text="Add record" runat="server"/><br>
<asp:label id="lbl_delete_ strSQL"
runat="server"/>

</td>
</tr>
</table>
<br><br><br>

<asp:Datagrid runat="server"
Id="testDataGri d"
Width="130"
GridLines="Both "
AutoGenerateCol umns="false"
BorderColor="si lver"
CellPadding="4"
CellSpacing="0"
AllowPaging="tr ue"
OnPageIndexChan ged="testPageGr id"
AllowSorting="t rue"
OnSortCommand=" testSortGrid"
BorderWidth="1"
PageSize="20"
Primarykey="tes t_id"
OnDeleteCommand ="Delete_Record _tblTest">

<headerstyle
Forecolor="#FFF FFF"
Font-Name="Tahoma"
Font-Size="100%"
Font-Bold="true"
BackColor="#FF0 000">
</headerstyle>

<itemstyle
Font-Name="Verdana"
Font-Size="70%"
VerticalAlign=" top"
BackColor="#FFF FFF">
</itemstyle>

<alternatingite mstyle
BackColor="#F4F 4F4">
</alternatingitem style>

<pagerstyle
Position="botto m"
Mode="NumericPa ges"
HorizontalAlign ="Center"
ForeColor="#FFF FFF"
BackColor="#FF0 000">
</pagerstyle>

<columns>

<asp:boundColum n
DataField="test _id"
SortExpression= "test_id"
HeaderText="ID"
ItemStyle-Wrap="false">
</asp:boundColumn >

<asp:boundColum n
DataField="test "
SortExpression= "test"
HeaderText="Tes t"
ItemStyle-Wrap="false">
</asp:boundColumn >

<asp:boundColum n
DataField="test 2"
SortExpression= "test2"
HeaderText="Tes t2"
ItemStyle-Wrap="false">
</asp:boundColumn >

<asp:ButtonColu mn
HeaderText=""
Text="Delete"
CommandName="de lete"/>
</columns>
</asp:DataGrid>
</form>

</body>
</html>
Nov 20 '05 #1
3 11801
Wrong newsgroup buddy, try adonet or asp

OHM
"Phi" <ph*******@hotm ail.com(remove) > wrote in message
news:Xn******** *************** ***********@194 .109.133.20...
Hi,

I hope somebody could help me with this problem.

I would like to make a form to add and delete records from my ms access
database. I've found most of the codes from the internet and adjusted
some part of it. Anyhow, inserting records to the database seems to work
fine, but deleting the records is not working as I want to and I just
can't see what's causing the problem.

Please, feel free to respond. Any comments/suggestion is welcome.

Thanks in advance for you help.

Kind regards,

Phi

code
========

<%@ Import Namespace="Syst em.Data" %>
<%@ Page Language = "vb" debug="true"%>
<%@ Import Namespace = "System.Data.Ol eDb" %>

<script language="vb" runat="server">
Private Sub Page_Load(sende r As Object, e As EventArgs)
If Not Page.IsPostBack Then
viewstate("sort Field") = "test_id"
viewstate("sort Direction") = "DESC"
testBindGrid()
End If
End Sub
sub onupdate(obj as object, e as eventargs)
dim StrSQl as string = "Insert into tbltest (test, test2 ) values
('" & tbx_test.text & "', '" & tbx_test2.text & "')"
ExecuteStatemen t(StrSQL)

testBindGrid()
End Sub

sub Delete_Record_t blTest(obj as object, e as DataGridCommand Eventargs)
dim strSQL as string = "delete from tbltest where test_id = " &
e.Item.ItemInde x
lbl_delete_strS QL.text = strsql
end sub

function ExecuteStatemen t(StrSQL)
Dim strConn As String = "Provider=Micro soft.Jet.Oledb. 4.0;" & "Data
Source=" & Server.MapPath( "/data/test.mdb") & ";"
Dim MyConn As New OleDBConnection (strConn)
dim objCmd as new OleDbCommand(St rSQL, MyConn)
objCmd.Connecti on.Open()
objCmd.ExeCuteN onQuery()

''close the connection to get the affected record in the table
objCmd.Connecti on.Close()
end function

Private Sub testBindGrid()
Dim strConn As string = "Provider=Micro soft.Jet.Oledb. 4.0;" & "Data
Source=" & Server.MapPath( "/data/test.mdb") & ";"
Dim MySQL As string = "SELECT tbltest.test_id , tbltest.test,
tbltest.test2 FROM tbltest ORDER BY " _
& viewstate("sort Field").ToStrin g() & " " & viewstate
("sortDirection ").ToString ()
Dim MyConn As New OleDBConnection (strConn)
Dim ds As DataSet = New DataSet()
Dim Cmd As New OleDBDataAdapte r(MySQL,MyConn)
Cmd.Fill(ds,"te st")

testDataGrid.Da taSource = ds
testDataGrid.Da tabind()

End Sub
Private Sub testPageGrid(By Val source As Object, ByVal e As
DataGridPageCha ngedEventArgs)
testDataGrid.Cu rrentPageIndex = e.NewPageIndex
testBindGrid()
End Sub

Private Sub testSortGrid(By Val source As Object, ByVal e As
DataGridSortCom mandEventArgs)
If e.SortExpressio n.ToString() = viewstate("sort Field").ToStrin g() Then
Select Case viewstate("sort Direction").ToS tring()
Case "ASC"
viewstate("sort Direction") = "DESC"
Case "DESC"
viewstate("sort Direction") = "ASC"
End Select
Else
viewstate("sort Field") = e.SortExpressio n
viewstate("sort Direction") = "DESC"
End If
testBindGrid()
End Sub

</script>
<html>

<body>

<form runat="server" method="post">
Insert Records in to the table Test<br><br>

<table>
<tr>
<td>test:</td>

<td><asp:textbo x id="tbx_test"
runat="server"/></td>
</tr>

<tr>
<td>test2:</td>

<td><asp:textbo x id="tbx_test2"
runat="server"/><br></td>
</tr>

<tr>
<td>

</td>

<td>

<asp:button id="button1" OnClick=
"onupdate" text="Add record" runat="server"/><br>
<asp:label id="lbl_delete_ strSQL"
runat="server"/>

</td>
</tr>
</table>
<br><br><br>

<asp:Datagrid runat="server"
Id="testDataGri d"
Width="130"
GridLines="Both "
AutoGenerateCol umns="false"
BorderColor="si lver"
CellPadding="4"
CellSpacing="0"
AllowPaging="tr ue"
OnPageIndexChan ged="testPageGr id"
AllowSorting="t rue"
OnSortCommand=" testSortGrid"
BorderWidth="1"
PageSize="20"
Primarykey="tes t_id"
OnDeleteCommand ="Delete_Record _tblTest">

<headerstyle
Forecolor="#FFF FFF"
Font-Name="Tahoma"
Font-Size="100%"
Font-Bold="true"
BackColor="#FF0 000">
</headerstyle>

<itemstyle
Font-Name="Verdana"
Font-Size="70%"
VerticalAlign=" top"
BackColor="#FFF FFF">
</itemstyle>

<alternatingite mstyle
BackColor="#F4F 4F4">
</alternatingitem style>

<pagerstyle
Position="botto m"
Mode="NumericPa ges"
HorizontalAlign ="Center"
ForeColor="#FFF FFF"
BackColor="#FF0 000">
</pagerstyle>

<columns>

<asp:boundColum n
DataField="test _id"
SortExpression= "test_id"
HeaderText="ID"
ItemStyle-Wrap="false">
</asp:boundColumn >

<asp:boundColum n
DataField="test "
SortExpression= "test"
HeaderText="Tes t"
ItemStyle-Wrap="false">
</asp:boundColumn >

<asp:boundColum n
DataField="test 2"
SortExpression= "test2"
HeaderText="Tes t2"
ItemStyle-Wrap="false">
</asp:boundColumn >

<asp:ButtonColu mn
HeaderText=""
Text="Delete"
CommandName="de lete"/>
</columns>
</asp:DataGrid>
</form>

</body>
</html>

Nov 20 '05 #2
Hello,

"Phi" <ph*******@hotm ail.com(remove) > schrieb:
I would like to make a form to add and delete records from my
ms access database.


This is a VB.NET language group. Notice that you will have a better
chance to get an answer if you post to the ADO.NET newsgroup in future:

news://msnews.microsoft.com/microsof...amework.adonet

Web interface:

http://msdn.microsoft.com/newsgroups...amework.adonet

--
Herfried K. Wagner
MVP · VB Classic, VB.NET
http://www.mvps.org/dotnet
Nov 20 '05 #3
phy
"Herfried K. Wagner [MVP]" <hi*******@m.ac tivevb.de> wrote in
news:ei******** ******@TK2MSFTN GP12.phx.gbl:
msnews.microsof t.com/microsoft.publi c.dotnet.framew ork.adonet


Sorry, I'm trying a new mailreader...
I pushed the button too soon..

Phi
Nov 20 '05 #4

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

8
4041
by: Steve | last post by:
I have several pairs of synchronized subforms in an application. I have a Delete button for each pair that uses the following code or similar to delete a record in the second subform: DoCmd.SetWarnings False DoCmd.RunCommand acCmdDeleteRecord DoCmd.SetWarnings True End If ExitHere: Me!SubName.SetFocus
4
9400
by: Stephen | last post by:
Hello People, Using MS Access 2003 VBA I get the error 3020 Update or CancelUpdate without AddNew or Edit when I run through the following code. Can anyone help suggest anything to try? Thanks. On Error GoTo delete_failed Dim RS_DEL As DAO.Recordset
4
7836
by: Susan Bricker | last post by:
I have a command button on a form that is supposed to Delete the record being displayed. The record is displayed one to a form. The form is not a Pop-Up nor is it Modal. Tracing the btnDelete event routine shows that AllowDeletions is TRUE. When the Delete button is clicked (without TRACE ON), I get a 'beep', the recordselector (vertical...
3
3432
by: Shapper | last post by:
Hello, I have created 3 functions to insert, update and delete an Access database record. The Insert and the Delete code are working fine. The update is not. I checked and my database has all the necessary records in it when testing it. I get the error "No value given for one or more required parameters." when I try to update the...
3
3417
by: bluez | last post by:
I want to design a webpage where user can search the data from the database and list out the related records. Each of the record got a delete button which allow user to delete the record. Filename : search_student.php <?php include("../user_access/user_access_control.php"); include("../Database/database.php"); $searchStudentControl =...
10
7149
beacon
by: beacon | last post by:
Hi everybody, This is probably going to sound unorthodox, but I have to log records that are deleted...I know, go figure. Anyway, I have a form with a (continuous) subform, and on the subform I have a command button, called cmdDelete, that launches a dialog form, called frmDeleteCurrentRecord, where the user has to enter their name and a...
6
3804
BeemerBiker
by: BeemerBiker | last post by:
I can't get rid of a "deleted" record in a database. Even if I delete it the record shows back up the next time I do an update. The following code generates an error message when using "driver=microsoft access driver (*.mdb)" Either in the app QTADO or in my own perl script that uses dbi:ODBC really simple command: "UPDATE mytable SET...
31
6645
by: matthewslyman | last post by:
I have an unusual design and some very unusual issues with my code... I have forced Access to cooperate on everything except one issue - record deletion. My form design involves a recursively nested form. In other words, the form, m_settings_menueditor_recursive has a single subform; m_settings_menueditor_recursive (both are viewed as...
0
7546
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main...
0
7471
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language...
0
7985
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that...
1
7503
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For...
0
7830
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the...
1
5387
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes...
0
5111
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert...
0
3496
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
1962
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.