Wrox Programmer Forums
|
ASP.NET 1.0 and 1.1 Basics ASP.NET discussion for users new to coding in ASP.NET 1.0 or 1.1. NOT for the older "classic" ASP 3 or the newer ASP.NET 2.0.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the ASP.NET 1.0 and 1.1 Basics section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
 
Old August 13th, 2003, 08:00 PM
Friend of Wrox
 
Join Date: Aug 2003
Posts: 108
Thanks: 0
Thanked 0 Times in 0 Posts
Send a message via ICQ to life_s Ng Send a message via MSN to life_s Ng
Default edit, update method

im creating a page which can update, insert, edit the contain of a microsoft access db. the update funtion got some problem n i cant solve it. i check the example from webside, but all i found is using sql db.

can any1 help me to take a look for it? pls copy n try run it, here is all the codes... thanks.

<%@ Page Language="VB" %>
<%@ import Namespace="System.Data" %>
<%@ import Namespace="System.Data.OleDb" %>
<script runat="server">

dim Conn as new OleDbConnection("Provider=Microsoft.jet.OLEDB.4.0; " &"Data Source=c:\Inetpub\wwwroot\db1.mdb")
sub Page_Load(Sender as Object, e as EventArgs)

if Not Page.IsPostBack then
FillDataGrid()
end if
end sub

sub Submit(Sender as Object, e as EventArgs)
dim i, j as integer
dim params(4) as string
dim strText as string
dim blnGo as boolean= true

j=0

for i = 0 to AddPanel.Controls.Count-1
if AddPanel.controls(i).GetType Is GetType(TextBox) then
strText=Ctype(AddPanel.Controls(i), TextBox).Text



if strText<>"" then
params(j)=strText
else
blnGo= false
lblMessage.Text=lblMessage.Text & "u forgot to enter a value for" & AddPanel.Controls(i).ID & lblMessage.Style("ForeColor")= "Red"
end if
j=j+1
end if
next

if not blnGo then
exit sub
end if


dim strsql as string= "INSERT INTO tbUser" & "(firstname, lastname, Address,"&" phone) VALUE ("& "'"& params(0) &"', " &"'"& params(1) &"', " &"'"& params(2) &"', " &"'"& params(3) &"')"
ExecuteStatement(strsql)

FillDataGrid()
end sub

' ----------------- edit, delete, update, cancel, and page changed methods-----------

sub dgData_Edit (Sender as object,e as DataGridCommandEventArgs)
FillDataGrid(e.Item.ItemIndex)
end sub

sub dgData_Delete(Sender as object, e as DataGridCommandEventArgs)
dim strsql as string="DELETE FROM tbUser" & "WHERE userid="& e.Item.ItemIndex + 1
ExecuteStatement(strsql)
FillDataGrid()
end sub

sub dgData_Cancel(Sender as object, e as DataGridCommandEventArgs)
FillDataGrid(-1)
end sub


' sub dgData_Update(Sender as object, e as DataGridCommandEventArgs)
' if UpdateStore (e as DataGridCommandEventArgs) then
' FillDataGrid(-1)
' end if
' end sub

sub dgData_PageIndexChanged(Sender as Object, e as DataGridPageChangedEventArgs)
dgData.DataBind()
end sub

'----------------------------------------------------------------

function UpdateStore (e as DataGridCommandEventArgs)as boolean

dim i,j as integer
dim params(4) as string
dim strText as string
dim blnGo as boolean= false
j=0


for i =1 to e.Item.Cells.Count-3
strText=Ctype(e.Item.Cells(i).Controls(0), TextBox).Text
if strText <> "" then
params(j)=strText
j=j+1

' else
' blnGo=false
' lblMessage.Text=lblMessage.Text & "u forgot to enter value!!<p>"
end if
next

if not blnGo then
return false
exit function
end if

dim strsql as string="UPDATE tbUser SET " & "firstname='" & params(0) & "'," &"lastname='" & params(1) & "'," &"Address='" & params(2) & "'," &"phone='" & params(3) & "'" & "WHERE userid="& Ctype(e.Item.Cells(0).Controls(1), Label).text

ExecuteStatement(strsql)
return blnGo
end function

sub FillDataGrid(Optional EditIndex as integer=-1)
dim objCmd as new OleDbCommand("select * from tbUser", Conn)
dim objReader as OleDbDataReader

try
objCmd.Connection.Open()
objReader= objCmd.ExecuteReader()
catch ex as Exception
lblmessage.Text=" error retrieving from database."
end try

dgData.DataSource=objReader
if not EditIndex.Equals(Nothing) then
dgData.EditItemIndex = EditIndex
end if

dgData.DataBind()

objReader.Close
objCmd.Connection.Close()

end sub

function ExecuteStatement(strsql)
dim objCmd as new OleDbCommand(strsql,Conn)

try
objCmd.Connection.Open()
objCmd.ExecuteNonQuery()
catch ex as Exception
lblMessage.Text= "error updating the database."
end try

objCmd.Connection.Close()
end function

</script>
<html>
<head>
</head>
<body>
<asp:Label id="lblMessage" runat="server"></asp:Label>
<form runat="server">
<asp:DataGrid id="dgData" runat="server" OnPageIndexChanged="dgData_PageIndexChanged" OnCancelCommand="dgData_Cancel" OnEditCommand="dgData_Edit" OnDeleteCommand="dgData_Delete" BorderColor="Black" GridLines="Vertical" cellpadding="4" width="100%" AutoGenerateColumns="false"> <%-- OnUpdateCommand="dgData_Update" --%>
<Columns>
<asp:TemplateColumn HeaderText="ID">
<ItemTemplate>
<asp:Label id="Name" runat="server" Text= '<%# Container.DataItem("userid")%>' />
</ItemTemplate>
</asp:TemplateColumn>

<asp:BoundColumn DataField="firstname" HeaderText="firstname"></asp:BoundColumn>
<asp:BoundColumn DataField="lastname" HeaderText="lastname "></asp:BoundColumn>
<asp:BoundColumn DataField="Address" HeaderText="Address"></asp:BoundColumn>
<asp:BoundColumn DataField="phone" HeaderText="phone"></asp:BoundColumn>
<asp:EditCommandColumn ButtonType="LinkButton" UpdateText="Update" HeaderText="Edit" CancelText="Cancel" EditText="Edit"></asp:EditCommandColumn>
<asp:ButtonColumn Text="Delete" CommandName="delete"></asp:ButtonColumn>

</Columns>
</asp:DataGrid>
<p>
<asp:Panel id="AddPanel" runat="server">
<table>
<tbody>
<tr>
<td valign="top" width="100">
first n last name:
</td>
<td valign="top" width="300">
<asp:TextBox id="tbFName" runat="server"></asp:TextBox>
<asp:TextBox id="tbLName" runat="server"></asp:TextBox>
</td>
</tr>
<tr>
<td valign="top">
Address:</td>
<td valign="top">
<asp:TextBox id="tbAddress" runat="server"></asp:TextBox>
</td>
</tr>
<tr>
<td valign="top">
phone:</td>
<td valign="top">
<asp:TextBox id="tbPhone" runat="server" size="11"></asp:TextBox>
<p></p>
</td>
</tr>
<tr>
<td valign="top" align="right" colspan="2">
<asp:Button id="btSubmit" onclick="Submit" runat="server" text="Add"></asp:Button>
</td>
</tr>
</tbody>
</table>
</asp:Panel>
</p>
</form>
</body>
</html>


 
Old August 14th, 2003, 07:48 AM
Registered User
 
Join Date: Aug 2003
Posts: 6
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Can you post your error message?

 
Old August 14th, 2003, 07:45 PM
Friend of Wrox
 
Join Date: Aug 2003
Posts: 108
Thanks: 0
Thanked 0 Times in 0 Posts
Send a message via ICQ to life_s Ng Send a message via MSN to life_s Ng
Default

Compiler Error Message: BC30455: Argument not specified for parameter 'e' of 'Public Function UpdateDataStore(e As System.Web.UI.WebControls.DataGridCommandEventArgs ) As Boolean'.
Line 63: sub dgData_Update(Sender as object, e as DataGridCommandEventArgs)
Line 64: if UpdateDataStore then 'error ..
Line 65: FillDataGrid(-1)


 
Old August 17th, 2003, 08:03 PM
Registered User
 
Join Date: Aug 2003
Posts: 6
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Did you let visual studio code for you?

 
Old August 17th, 2003, 10:24 PM
Friend of Wrox
 
Join Date: Aug 2003
Posts: 108
Thanks: 0
Thanked 0 Times in 0 Posts
Send a message via ICQ to life_s Ng Send a message via MSN to life_s Ng
Default

Quote:
quote:Originally posted by mm111mm222
 Did you let visual studio code for you?

nope, i nv learn about Visual studio... im using web matrix. how to let visual studio code for me?

 
Old August 19th, 2003, 10:45 PM
Friend of Wrox
 
Join Date: Aug 2003
Posts: 108
Thanks: 0
Thanked 0 Times in 0 Posts
Send a message via ICQ to life_s Ng Send a message via MSN to life_s Ng
Default

yes! it can work already, its bcoz of the call method, the parameter of "function updateStore" is (e as Data.....)
then i should call it from update method as below:

if updateStore(e) then
.
.
.









Similar Threads
Thread Thread Starter Forum Replies Last Post
Update or CancelUpdate without AddNew or Edit ru1 Access 1 October 15th, 2005 02:24 PM
Edit method knowledge76 Access VBA 3 April 28th, 2005 02:52 AM
how to edit and update my access db using asp.net method ASP.NET 1.0 and 1.1 Basics 4 April 25th, 2005 03:03 PM
rst.edit method Sympac Access 0 August 30th, 2004 03:50 PM
edit-update record- help TnTandyO Classic ASP Databases 37 September 11th, 2003 06:31 PM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.