Thursday, March 29, 2012
Newbie - Where Can I Get Examples To Learn From
As I am completing the ASP.NET Developer's Jumpstart book, I find there are
many things I want to do that are not covered in the book (I don't expect it
to have everything).
I learn best when I "play" with an already working page and disect it. I
went to www.asp.net and they have many starter kits, but either they are
too complicated for me, don't work (I am sure it is me and not them) or not
what I am looking for. It is not a slam on that page at all, I think it is a
great resource.
Does anyone have some suggestion on example pages that I can learn from? Or
maybe a book?
Thanks.
-RobHi Rob,
Are you new to ASP.NET in particular, or Web development in general?
IF you are new to Web development in general, then I'd suggest you start
with the basics - as taught in this wonderful e-book tutorial...
http://www.projectseven.com/books/f...onsmx/index.htm
You'll need Dreamweaver to do it, but if you are serious about learning Web
development fundamentals, then you'll like the control you get with
Dreamweaver. The e-book is NOT a Dreamweaver tutorial; rather it shows you
the fundamentals of solid Web page design (and walks you through everything
step-by-step using Dreamweaver). Highly recommended for any HTML/Web page
beginner.
IF you already know sound Web page design and HTML and are trying to get up
to speed on ASP.NET in particular, then I'd strongly recommend you stick
with the ASP.NET starter kits... specifically the Commerce application.
Learn what is all included in the tutorial package and take your time. It
will be well worth it. Learn how the documentation is organized and then
dive into the code - using the documentation as your tour guide.
Good Luck
G
"Rob G" <gumbatman@.hotmail.com> wrote in message
news:10ank0qk4vtut78@.corp.supernews.com...
> Hi All,
> As I am completing the ASP.NET Developer's Jumpstart book, I find there
are
> many things I want to do that are not covered in the book (I don't expect
it
> to have everything).
> I learn best when I "play" with an already working page and disect it. I
> went to www.asp.net and they have many starter kits, but either they are
> too complicated for me, don't work (I am sure it is me and not them) or
not
> what I am looking for. It is not a slam on that page at all, I think it is
a
> great resource.
> Does anyone have some suggestion on example pages that I can learn from?
Or
> maybe a book?
> Thanks.
> -Rob
>
> As I am completing the ASP.NET Developer's Jumpstart book, I find there are
> many things I want to do that are not covered in the book (I don't expect
it
> to have everything).
If you are familiar with Web development and just looking to learn
ASP.NET, I'd recommend:
ASP.NET Unleashed
http://www.amazon.com/exec/obidos/A...guysfromrollaco
ASP.NET KickStart
http://www.amazon.com/exec/obidos/A...guysfromrollaco
Both are written by Stephen Walther.
There are also a number of Web sites with loads of great, free information:
http://www.asp.net
http://www.4guysfromrolla.com
http://www.aspalliance.com
http://www.dotnetjunkies.com
http://msdn.microsoft.com/aspnet
And many others...
Hope this helps!
Scott Mitchell
mitchell@.4guysfromrolla.com
http://www.4GuysFromRolla.com
http://www.ASPFAQs.com
http://www.ASPMessageboard.com
* When you think ASP, think 4GuysFromRolla.com!
Grant and Scott,
Thank you both for the great information. It will really get me started.
-Rob
"Scott Mitchell [MVP]" <mitchell@.4guysfromrolla.com> wrote in message
news:40ABDFCF.7010808@.4guysfromrolla.com...
are
expect it
> If you are familiar with Web development and just looking to learn
> ASP.NET, I'd recommend:
> ASP.NET Unleashed
> http://www.amazon.com/exec/obidos/A...guysfromrollaco
> ASP.NET KickStart
> http://www.amazon.com/exec/obidos/A...guysfromrollaco
> Both are written by Stephen Walther.
> There are also a number of Web sites with loads of great, free
information:
> http://www.asp.net
> http://www.4guysfromrolla.com
> http://www.aspalliance.com
> http://www.dotnetjunkies.com
> http://msdn.microsoft.com/aspnet
> And many others...
> Hope this helps!
> --
> Scott Mitchell
> mitchell@.4guysfromrolla.com
> http://www.4GuysFromRolla.com
> http://www.ASPFAQs.com
> http://www.ASPMessageboard.com
> * When you think ASP, think 4GuysFromRolla.com!
The .Net SDK is free from Microsoft:
http://www.microsoft.com/downloads/...&displaylang=en
HTH,
Kevin Spencer
.Net Developer
Microsoft MVP
Big things are made up
of lots of little things.
"Rob G" <gumbatman@.hotmail.com> wrote in message
news:10ank0qk4vtut78@.corp.supernews.com...
> Hi All,
> As I am completing the ASP.NET Developer's Jumpstart book, I find there
are
> many things I want to do that are not covered in the book (I don't expect
it
> to have everything).
> I learn best when I "play" with an already working page and disect it. I
> went to www.asp.net and they have many starter kits, but either they are
> too complicated for me, don't work (I am sure it is me and not them) or
not
> what I am looking for. It is not a slam on that page at all, I think it is
a
> great resource.
> Does anyone have some suggestion on example pages that I can learn from?
Or
> maybe a book?
> Thanks.
> -Rob
>
Newbie - Where Can I Get Examples To Learn From
As I am completing the ASP.NET Developer's Jumpstart book, I find there are
many things I want to do that are not covered in the book (I don't expect it
to have everything).
I learn best when I "play" with an already working page and disect it. I
went to www.asp.net and they have many starter kits, but either they are
too complicated for me, don't work (I am sure it is me and not them) or not
what I am looking for. It is not a slam on that page at all, I think it is a
great resource.
Does anyone have some suggestion on example pages that I can learn from? Or
maybe a book?
Thanks.
-RobHi Rob,
Are you new to ASP.NET in particular, or Web development in general?
IF you are new to Web development in general, then I'd suggest you start
with the basics - as taught in this wonderful e-book tutorial...
http://www.projectseven.com/books/f...onsmx/index.htm
You'll need Dreamweaver to do it, but if you are serious about learning Web
development fundamentals, then you'll like the control you get with
Dreamweaver. The e-book is NOT a Dreamweaver tutorial; rather it shows you
the fundamentals of solid Web page design (and walks you through everything
step-by-step using Dreamweaver). Highly recommended for any HTML/Web page
beginner.
IF you already know sound Web page design and HTML and are trying to get up
to speed on ASP.NET in particular, then I'd strongly recommend you stick
with the ASP.NET starter kits... specifically the Commerce application.
Learn what is all included in the tutorial package and take your time. It
will be well worth it. Learn how the documentation is organized and then
dive into the code - using the documentation as your tour guide.
Good Luck
G
"Rob G" <gumbatman@.hotmail.com> wrote in message
news:10ank0qk4vtut78@.corp.supernews.com...
> Hi All,
> As I am completing the ASP.NET Developer's Jumpstart book, I find there
are
> many things I want to do that are not covered in the book (I don't expect
it
> to have everything).
> I learn best when I "play" with an already working page and disect it. I
> went to www.asp.net and they have many starter kits, but either they are
> too complicated for me, don't work (I am sure it is me and not them) or
not
> what I am looking for. It is not a slam on that page at all, I think it is
a
> great resource.
> Does anyone have some suggestion on example pages that I can learn from?
Or
> maybe a book?
> Thanks.
> -Rob
> As I am completing the ASP.NET Developer's Jumpstart book, I find there are
> many things I want to do that are not covered in the book (I don't expect it
> to have everything).
If you are familiar with Web development and just looking to learn
ASP.NET, I'd recommend:
ASP.NET Unleashed
http://www.amazon.com/exec/obidos/A...guysfromrollaco
ASP.NET KickStart
http://www.amazon.com/exec/obidos/A...guysfromrollaco
Both are written by Stephen Walther.
There are also a number of Web sites with loads of great, free information:
http://www.asp.net
http://www.4guysfromrolla.com
http://www.aspalliance.com
http://www.dotnetjunkies.com
http://msdn.microsoft.com/aspnet
And many others...
Hope this helps!
--
Scott Mitchell
mitchell@.4guysfromrolla.com
http://www.4GuysFromRolla.com
http://www.ASPFAQs.com
http://www.ASPMessageboard.com
* When you think ASP, think 4GuysFromRolla.com!
Grant and Scott,
Thank you both for the great information. It will really get me started.
-Rob
"Scott Mitchell [MVP]" <mitchell@.4guysfromrolla.com> wrote in message
news:40ABDFCF.7010808@.4guysfromrolla.com...
> > As I am completing the ASP.NET Developer's Jumpstart book, I find there
are
> > many things I want to do that are not covered in the book (I don't
expect it
> > to have everything).
> If you are familiar with Web development and just looking to learn
> ASP.NET, I'd recommend:
> ASP.NET Unleashed
> http://www.amazon.com/exec/obidos/A...guysfromrollaco
> ASP.NET KickStart
> http://www.amazon.com/exec/obidos/A...guysfromrollaco
> Both are written by Stephen Walther.
> There are also a number of Web sites with loads of great, free
information:
> http://www.asp.net
> http://www.4guysfromrolla.com
> http://www.aspalliance.com
> http://www.dotnetjunkies.com
> http://msdn.microsoft.com/aspnet
> And many others...
> Hope this helps!
> --
> Scott Mitchell
> mitchell@.4guysfromrolla.com
> http://www.4GuysFromRolla.com
> http://www.ASPFAQs.com
> http://www.ASPMessageboard.com
> * When you think ASP, think 4GuysFromRolla.com!
The .Net SDK is free from Microsoft:
http://www.microsoft.com/downloads/...&displaylang=en
--
HTH,
Kevin Spencer
..Net Developer
Microsoft MVP
Big things are made up
of lots of little things.
"Rob G" <gumbatman@.hotmail.com> wrote in message
news:10ank0qk4vtut78@.corp.supernews.com...
> Hi All,
> As I am completing the ASP.NET Developer's Jumpstart book, I find there
are
> many things I want to do that are not covered in the book (I don't expect
it
> to have everything).
> I learn best when I "play" with an already working page and disect it. I
> went to www.asp.net and they have many starter kits, but either they are
> too complicated for me, don't work (I am sure it is me and not them) or
not
> what I am looking for. It is not a slam on that page at all, I think it is
a
> great resource.
> Does anyone have some suggestion on example pages that I can learn from?
Or
> maybe a book?
> Thanks.
> -Rob
Saturday, March 24, 2012
Newbie getting very frustrated....
In hour 3 and 4 of the book they have you making a Mortgage Calculator. So i have spent a few days working on this. I cannot seem to get this. I keep getting error after error. And yet when i look at the code, it is typed the same way it is in the lessons. And yet, at the end of the lsessons, it doesn't go into depth or anything about if the project doesnt work, or what happens when you get these errors.
Anyone have this book, that can help me out? I really need to learn this. And i have been told this book is a wastse of myt ime. But it was the only book the Barnes and Nobles had on ASP.Net.
So i guess i am stuck with it. Here is the code...
Sub performCalc_Click(sender As Object, e As EventArgs)
'Specify constant values
Const INTEREST_CALCS_PER_YEAR as Integer = 12
Const PAYMENTS_PER_YEAR as Integer = 12
'Create variables to hold the values entered by the user
Dim P as Double = loanAmount.Text
Dim r as Double = rate.Text / 100
Dim t as Double = mortgageLength.Text
Dim ratePerPeriod as Double
ratePerPeriod = r/INTEREST_CALCS_PER_YEAR
Dim payPeriods as Integer
payPeriods = t * PAYMENTS_PER_YEAR
Dim annualRate as Double
annualRate = Math.Exp(INTEREST_CALCS_PER_YEAR *
Math.Log(1+ratePerPeriod)) - 1
Dim intPerPayment as Double
intPerPayment = (Math.Exp(Math.Log(annualRate+1)/payPeriods) -1 *
payPeriods
'Now compute the total cost of the loan
Dim intPerMonth as Double = intPerPayment / PAYMENTS_PER_YEAR
Dim costPerMonth as Double
costPerMonth = P * intPerMonth/(1-Math.Pow(intPerMonth+1,-payPeriods))
'Now display the results in the results Label Web Control
results.Text = "Your mortgage payment per month is $" & costPerMonth
End SubI tried your posted code after adding the 3 necessary textboxes, one label and one button - -
The only problem I could find is line 26:
intPerPayment = (Math.Exp(Math.Log(annualRate+1)/payPeriods) -1 * payPeriods
should be:
intPerPayment = (Math.Exp(Math.Log(annualRate+1)/payPeriods) -1) * payPeriods
(notice the parenthesis after the -1)
Then, it worked fine for me
Do you have a specific error?
I suggest getting the ASP.NET Unleashed by SAMS
and if you are using VB then the Programming Microsoft Visual Basic .NET by Francesco Balena.
Both of these are ausome books.
Be careful, there are a lot of useless books out there.
ok i added that )
but the error i keep getting is here.
Line 23:
Line 24: Dim annualRate as Double
Line 25: annualRate = Math.Exp(INTEREST_CALCS_PER_YEAR *
Line 26: Math.Log(1+ratePerPeriod)) -1
Line 27:
LINE 25....
i even added the ) mark after the -1, and it still gave me an error.
The error says: Compiler Error Message: BC30201: Expression expected
but in my case, i will gaurentee, that if i get this one fixed, i will get another. :) it has been happening since i started this project...lol
Here is the detailed complier output:
Microsoft (R) Visual Basic .NET Compiler version 7.10.6001.4
for Microsoft (R) .NET Framework version 1.1.4322.2032
Copyright (C) Microsoft Corporation 1987-2002. All rights reserved.
C:\Documents and Settings\Administrator\My Documents\FinancialCalculator.aspx(25) : error BC30201: Expression expected.
annualRate = Math.Exp(INTEREST_CALCS_PER_YEAR *
~
C:\Documents and Settings\Administrator\My Documents\FinancialCalculator.aspx(26) : error BC30205: End of statement expected.
Math.Log(1+ratePerPeriod)) -1)
~~~~~
C:\Documents and Settings\Administrator\My Documents\FinancialCalculator.aspx(29) : error BC30201: Expression expected.
intPerPayment = (Math.Exp(Math.Log(annualRate+1)/payPeriods) -1) *
~
C:\Documents and Settings\Administrator\My Documents\FinancialCalculator.aspx(30) : error BC30454: Expression is not a method.
payPeriods
~~~~~~~~~~
If your code shown here is exactly what you see in your editor then you need to add underscores ( _ ) at the end of each line before hitting "return" to break up the line of code. currently, the processor thinks that what you have is 2 different lines of code. I fear I'm not saying this well...better to show you...
Line 25: annualRate = Math.Exp(INTEREST_CALCS_PER_YEAR * _
Line 26: Math.Log(1+ratePerPeriod)) -1
You may also want to check the rest of your code
Dim intPerPayment as Double
intPerPayment = (Math.Exp(Math.Log(annualRate+1)/payPeriods) -1 * _
payPeriods
Try not to lose your patience...remember, errors are a newbie's friend. They will make you stronger and smarter. :) I know, I'm a newbie.
Thank you. that worked. it gave me one more error, but i placed the ) mark after the -1.
so it looked like:
Dim intPerPayment as Double
intPerPayment = (Math.Exp(Math.Log(annualRate+1)/payPeriods) -1) * _
payPeriods
This books so far sahid nothing about the underscore after the lines to seperate them. Again i thank you. This put a smile on my face for the day.
Sorry I missed that - - I did see the continuation of the line and corrected it on my end, but I just thought that's the way it copied to my system - - didn't think it was the actual way it was in the section I copied....I've run into that several times, on the web, and just didn't think twice about fixing the line automatically
Ahh the underscore...
I've run across quite a few books that just wrap the line of code in their examples. So if you were just copying the code directly from the book you would end up with errors. Just be on the look out for things like that.
NEWBIE has a prob
framework 1.1. I run Win XP Pro SP1 and IIS 5.1.
The problem:
I 've tried to run two different .aspx files and the browser displays simple
html (text) but no forms or anything like that. IE keeps giving this error
"Line: 4, Char:6, Error:Expected ';', Code:0", but I've checked the code and
is fine. Everything works ok with good old ASP.
Any idea what this annoyance might be?
Thank you all in advance.You may need to repair your IIS mappings.
To do this, run the following command:
aspnet_regiis.exe -i
Here's further information:
http://support.microsoft.com/defaul...B;EN-US;q306005
--
I hope this helps,
Steve C. Orr, MCSD
http://Steve.Orr.net
"Hugo Bohorquez" <hugob@.sympatico.ca> wrote in message
news:JOmYa.6040$pq5.811642@.news20.bellglobal.com.. .
> Hello, I have just picked up a book on ASP.NET and installed the .NET
> framework 1.1. I run Win XP Pro SP1 and IIS 5.1.
> The problem:
> I 've tried to run two different .aspx files and the browser displays
simple
> html (text) but no forms or anything like that. IE keeps giving this error
> "Line: 4, Char:6, Error:Expected ';', Code:0", but I've checked the code
and
> is fine. Everything works ok with good old ASP.
> Any idea what this annoyance might be?
> Thank you all in advance.
Newbie help!
I am reading a book on ASP.NET and the following code is from the book
(Teach Yourself ASP.NET in 21 Days by Chris Payne). I have typed the
code in notepad and I am having a problem with it that I hope someone
can help. Basically there is a Submit button which is supposed to
update an Access database, but for some reason it keeps on erroring
out. I have it in a try-catch block and I cannot get the update or
delete to work without error. The following is the code from the book.
Thank you in advance for your help!!!
<%@dotnet.itags.org. Page language="VB" %>
<%@dotnet.itags.org. import namespace="system.data" %>
<%@dotnet.itags.org. import namespace="system.data.oledb" %
<script runat="server">
'declare connection
dim conn as new oledbconnection("Provider=Microsoft.Jet.OLEDB.4.0;
Data source=C:\Inetpub\wwwroot\Day8\banking.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)
'insert new data
dim i, j as integer
dim params(7) 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 & "You forgot to add a
value for " & addpanel.controls(i).id & "<p>"
lblmessage.style("Forecolor") = "red"
end if
j = j + 1
end if
next i
if not blngo then
exit sub
end if
dim strsql as string = "INSERT INTO Users (FirstName, LastName,
Address, City, State, Zip, Phone) VALUES (" & _
"'" & params(0) & "'," & _
"'" & params(1) & "'," & _
"'" & params(2) & "'," & _
"'" & params(3) & "'," & _
"'" & params(4) & "'," & _
"'" & params(5) & "'," & _
"'" & params(6) & "')"
executestatement(strsql)
filldatagrid()
end sub
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 = "DELETE FROM Users WHERE ID = " & e.item.itemindex
executestatement(strsql)
filldatagrid()
end sub
sub dgdata_update(sender as object, e as datagridcommandeventargs)
if updatedatastore(e) then
filldatagrid(-1)
end if
end sub
sub dgdata_cancel(sender as object, e as datagridcommandeventargs)
filldatagrid(-1)
end sub
sub dgdata_pageindexchanged(sender as object, e as
datagridpagechangedeventargs)
dgdata.databind()
end sub
function updatedatastore(e as datagridcommandeventargs) as boolean
dim i,j as integer
dim params(7) as string
dim strtext as string
dim blnGo as boolean = true
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
else
blngo = false
lblmessage.text = lblmessage.text & "You forgot to enter a
value <p>"
end if
next i
if not blngo then
return false
exit function
end if
dim strsql as string = "UPDATE Users SET " & _
"FirstName = '" & params(0) & "'," & _
"LastName = '" & params(1) & "'," & _
"Address = '" & params(2) & "'," & _
"City = '" & params(3) & "'," & _
"State = '" & params(4) & "'," & _
"Zip = '" & params(5) & "'," & _
"Phone = '" & params(6) & "' " & _
"WHERE ID = " &
ctype(e.item.cells(0).controls(1),label).text
executestatement(strsql)
return blngo
end function
sub filldatagrid(optional editindex as integer = -1)
'open connection
dim objcmd as new oledbcommand("select * from Users", conn)
dim objreader as oledbdatareader
try
objcmd.connection.open()
objreader = objcmd.executereader()
catch ex as exception
lblMessage.text = "Error retrieving from the 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 as string)
'open connection
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><body>
<asp:Label id="lblMessage" runat="server"/
<form runat="server">
<asp:Datagrid id="dgData" runat="server"
BorderColor="Black" gridlines="vertical"
cellpadding="4" cellspacing="0" width="100%"
autogeneratecolumns="false"
ondeletecommand="dgData_Delete"
onEditcommand="dgData_Edit"
onCancelcommand="dgData_Cancel"
onUpdatecommand="dgData_Update"
onpageindexchanged="dgData_PageIndexChanged"
<columns>
<asp:TemplateColumn headertext="ID">
<itemtemplate>
<asp:Label id="Name" text='<%#
container.dataitem("ID") %>' runat="server"/>
</itemtemplate>
</asp:templatecolumn
<asp:boundcolumn headertext="First Name"
datafield="FirstName"/>
<asp:boundcolumn headertext="Last Name"
datafield="LastName"/>
<asp:boundcolumn headertext="Address" datafield="Address"/>
<asp:boundcolumn headertext="City" datafield="City"/>
<asp:boundcolumn headertext="State" datafield="State"/>
<asp:boundcolumn headertext="Zip" datafield="Zip"/>
<asp:boundcolumn headertext="Phone" datafield="Phone"/
<asp:editcommandcolumn edittext="Edit" canceltext="Cancel"
updatetext="Update" headertext="Edit"/>
<asp:buttoncolumn headertext="" text="Delete"
commandname="Delete"/>
</columns>
</asp:datagrid><p
<asp:panel id="AddPanel" runat="server">
<table>
<tr>
<td width="100" valign="top">First and last name: </td>
<td width="300" valign="top">
<asp:textbox id="tbFName" runat="server"/>
<asp:textbox id="tbLName" runat="server"/>
</td>
</tr
<tr>
<td width="100" valign="top">Address: </td>
<td width="300" valign="top">
<asp:textbox id="tbAddress" runat="server"/>
</td>
</tr
<tr>
<td width="100" valign="top">City, State, Zip: </td>
<td width="300" valign="top">
<asp:textbox id="tbCity" runat="server"/>,
<asp:textbox id="tbState" size=2
runat="server"/>
<asp:textbox id="tbZip" size=5 runat="server"/>
</td>
</tr
<tr>
<td width="100" valign="top">Phone: </td>
<td width="300" valign="top">
<asp:textbox id="tbPhone" size=11 runat="server"/>
</td>
</tr
<tr>
<td colspan=2 valign="top" align="right">
<asp:Button id="btSubmit" text="Add" onclick="Submit"
runat="server"/>
</td>
</tr>
</table>
</asp:panel>
</form>
</body></htmlTwo things. !
1.) Go and buy visual studio, you really wont go far using notepad (
Although you can get by without it, it will be a nightmare )
2.) You dont say what the error is.?
--
( OHM ) - One Handed Man
AKA Terry Burns - http://TrainingOn.net
<MPotok@.gmail.com> wrote in message
news:1145338918.804159.312510@.v46g2000cwv.googlegr oups.com...
> Hi,
> I am reading a book on ASP.NET and the following code is from the book
> (Teach Yourself ASP.NET in 21 Days by Chris Payne). I have typed the
> code in notepad and I am having a problem with it that I hope someone
> can help. Basically there is a Submit button which is supposed to
> update an Access database, but for some reason it keeps on erroring
> out. I have it in a try-catch block and I cannot get the update or
> delete to work without error. The following is the code from the book.
> Thank you in advance for your help!!!
> <%@. Page language="VB" %>
> <%@. import namespace="system.data" %>
> <%@. import namespace="system.data.oledb" %>
> <script runat="server">
> 'declare connection
> dim conn as new oledbconnection("Provider=Microsoft.Jet.OLEDB.4.0;
> Data source=C:\Inetpub\wwwroot\Day8\banking.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)
> 'insert new data
> dim i, j as integer
> dim params(7) 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 & "You forgot to add a
> value for " & addpanel.controls(i).id & "<p>"
> lblmessage.style("Forecolor") = "red"
> end if
> j = j + 1
> end if
> next i
> if not blngo then
> exit sub
> end if
> dim strsql as string = "INSERT INTO Users (FirstName, LastName,
> Address, City, State, Zip, Phone) VALUES (" & _
> "'" & params(0) & "'," & _
> "'" & params(1) & "'," & _
> "'" & params(2) & "'," & _
> "'" & params(3) & "'," & _
> "'" & params(4) & "'," & _
> "'" & params(5) & "'," & _
> "'" & params(6) & "')"
> executestatement(strsql)
> filldatagrid()
> end sub
> 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 = "DELETE FROM Users WHERE ID = " & e.item.itemindex
> executestatement(strsql)
> filldatagrid()
> end sub
> sub dgdata_update(sender as object, e as datagridcommandeventargs)
> if updatedatastore(e) then
> filldatagrid(-1)
> end if
> end sub
> sub dgdata_cancel(sender as object, e as datagridcommandeventargs)
> filldatagrid(-1)
> end sub
> sub dgdata_pageindexchanged(sender as object, e as
> datagridpagechangedeventargs)
> dgdata.databind()
> end sub
> function updatedatastore(e as datagridcommandeventargs) as boolean
> dim i,j as integer
> dim params(7) as string
> dim strtext as string
> dim blnGo as boolean = true
> 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
> else
> blngo = false
> lblmessage.text = lblmessage.text & "You forgot to enter a
> value <p>"
> end if
> next i
> if not blngo then
> return false
> exit function
> end if
> dim strsql as string = "UPDATE Users SET " & _
> "FirstName = '" & params(0) & "'," & _
> "LastName = '" & params(1) & "'," & _
> "Address = '" & params(2) & "'," & _
> "City = '" & params(3) & "'," & _
> "State = '" & params(4) & "'," & _
> "Zip = '" & params(5) & "'," & _
> "Phone = '" & params(6) & "' " & _
> "WHERE ID = " &
> ctype(e.item.cells(0).controls(1),label).text
> executestatement(strsql)
> return blngo
> end function
> sub filldatagrid(optional editindex as integer = -1)
> 'open connection
> dim objcmd as new oledbcommand("select * from Users", conn)
> dim objreader as oledbdatareader
> try
> objcmd.connection.open()
> objreader = objcmd.executereader()
> catch ex as exception
> lblMessage.text = "Error retrieving from the 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 as string)
> 'open connection
> 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><body>
> <asp:Label id="lblMessage" runat="server"/>
> <form runat="server">
> <asp:Datagrid id="dgData" runat="server"
> BorderColor="Black" gridlines="vertical"
> cellpadding="4" cellspacing="0" width="100%"
> autogeneratecolumns="false"
> ondeletecommand="dgData_Delete"
> onEditcommand="dgData_Edit"
> onCancelcommand="dgData_Cancel"
> onUpdatecommand="dgData_Update"
> onpageindexchanged="dgData_PageIndexChanged">
> <columns>
> <asp:TemplateColumn headertext="ID">
> <itemtemplate>
> <asp:Label id="Name" text='<%#
> container.dataitem("ID") %>' runat="server"/>
> </itemtemplate>
> </asp:templatecolumn>
> <asp:boundcolumn headertext="First Name"
> datafield="FirstName"/>
> <asp:boundcolumn headertext="Last Name"
> datafield="LastName"/>
> <asp:boundcolumn headertext="Address" datafield="Address"/>
> <asp:boundcolumn headertext="City" datafield="City"/>
> <asp:boundcolumn headertext="State" datafield="State"/>
> <asp:boundcolumn headertext="Zip" datafield="Zip"/>
> <asp:boundcolumn headertext="Phone" datafield="Phone"/>
> <asp:editcommandcolumn edittext="Edit" canceltext="Cancel"
> updatetext="Update" headertext="Edit"/>
> <asp:buttoncolumn headertext="" text="Delete"
> commandname="Delete"/>
> </columns>
> </asp:datagrid><p>
> <asp:panel id="AddPanel" runat="server">
> <table>
> <tr>
> <td width="100" valign="top">First and last name: </td>
> <td width="300" valign="top">
> <asp:textbox id="tbFName" runat="server"/>
> <asp:textbox id="tbLName" runat="server"/>
> </td>
> </tr>
> <tr>
> <td width="100" valign="top">Address: </td>
> <td width="300" valign="top">
> <asp:textbox id="tbAddress" runat="server"/>
> </td>
> </tr>
> <tr>
> <td width="100" valign="top">City, State, Zip: </td>
> <td width="300" valign="top">
> <asp:textbox id="tbCity" runat="server"/>,
> <asp:textbox id="tbState" size=2
> runat="server"/>
> <asp:textbox id="tbZip" size=5 runat="server"/>
> </td>
> </tr>
> <tr>
> <td width="100" valign="top">Phone: </td>
> <td width="300" valign="top">
> <asp:textbox id="tbPhone" size=11 runat="server"/>
> </td>
> </tr>
> <tr>
> <td colspan=2 valign="top" align="right">
> <asp:Button id="btSubmit" text="Add" onclick="Submit"
> runat="server"/>
> </td>
> </tr>
> </table>
> </asp:panel>
> </form>
> </body></html
Or download VWD Express Edition for free (For a year anyway). I've been
using it a few weeks from a standing start and whilst I code for fun have
built a great KPI dashboard for work which updates continuously throughout
the day...really productive
http://msdn.microsoft.com/vstudio/express/vwd/
--
HTH
Nick Hodge
Microsoft MVP - Excel
Southampton, England
www.nickhodge.co.uk
nick_hodgeTAKETHISOUT@.zen.co.uk.ANDTHIS
"OHM ( One Handed Man )" <me@.mine.com> wrote in message
news:uKLso9qYGHA.4620@.TK2MSFTNGP04.phx.gbl...
> Two things. !
> 1.) Go and buy visual studio, you really wont go far using notepad (
> Although you can get by without it, it will be a nightmare )
> 2.) You dont say what the error is.?
> --
> ( OHM ) - One Handed Man
> AKA Terry Burns - http://TrainingOn.net
>
> <MPotok@.gmail.com> wrote in message
> news:1145338918.804159.312510@.v46g2000cwv.googlegr oups.com...
>> Hi,
>>
>> I am reading a book on ASP.NET and the following code is from the book
>> (Teach Yourself ASP.NET in 21 Days by Chris Payne). I have typed the
>> code in notepad and I am having a problem with it that I hope someone
>> can help. Basically there is a Submit button which is supposed to
>> update an Access database, but for some reason it keeps on erroring
>> out. I have it in a try-catch block and I cannot get the update or
>> delete to work without error. The following is the code from the book.
>>
>> Thank you in advance for your help!!!
>>
>> <%@. Page language="VB" %>
>> <%@. import namespace="system.data" %>
>> <%@. import namespace="system.data.oledb" %>
>>
>> <script runat="server">
>> 'declare connection
>> dim conn as new oledbconnection("Provider=Microsoft.Jet.OLEDB.4.0;
>> Data source=C:\Inetpub\wwwroot\Day8\banking.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)
>> 'insert new data
>> dim i, j as integer
>> dim params(7) 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 & "You forgot to add a
>> value for " & addpanel.controls(i).id & "<p>"
>> lblmessage.style("Forecolor") = "red"
>> end if
>> j = j + 1
>> end if
>> next i
>>
>> if not blngo then
>> exit sub
>> end if
>>
>> dim strsql as string = "INSERT INTO Users (FirstName, LastName,
>> Address, City, State, Zip, Phone) VALUES (" & _
>> "'" & params(0) & "'," & _
>> "'" & params(1) & "'," & _
>> "'" & params(2) & "'," & _
>> "'" & params(3) & "'," & _
>> "'" & params(4) & "'," & _
>> "'" & params(5) & "'," & _
>> "'" & params(6) & "')"
>>
>> executestatement(strsql)
>> filldatagrid()
>> end sub
>>
>> 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 = "DELETE FROM Users WHERE ID = " & e.item.itemindex
>>
>> executestatement(strsql)
>> filldatagrid()
>> end sub
>>
>> sub dgdata_update(sender as object, e as datagridcommandeventargs)
>> if updatedatastore(e) then
>> filldatagrid(-1)
>> end if
>> end sub
>>
>> sub dgdata_cancel(sender as object, e as datagridcommandeventargs)
>> filldatagrid(-1)
>> end sub
>>
>> sub dgdata_pageindexchanged(sender as object, e as
>> datagridpagechangedeventargs)
>> dgdata.databind()
>> end sub
>>
>> function updatedatastore(e as datagridcommandeventargs) as boolean
>> dim i,j as integer
>> dim params(7) as string
>> dim strtext as string
>> dim blnGo as boolean = true
>>
>> 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
>> else
>> blngo = false
>> lblmessage.text = lblmessage.text & "You forgot to enter a
>> value <p>"
>> end if
>> next i
>>
>> if not blngo then
>> return false
>> exit function
>> end if
>>
>> dim strsql as string = "UPDATE Users SET " & _
>> "FirstName = '" & params(0) & "'," & _
>> "LastName = '" & params(1) & "'," & _
>> "Address = '" & params(2) & "'," & _
>> "City = '" & params(3) & "'," & _
>> "State = '" & params(4) & "'," & _
>> "Zip = '" & params(5) & "'," & _
>> "Phone = '" & params(6) & "' " & _
>> "WHERE ID = " &
>> ctype(e.item.cells(0).controls(1),label).text
>>
>> executestatement(strsql)
>> return blngo
>> end function
>>
>> sub filldatagrid(optional editindex as integer = -1)
>> 'open connection
>> dim objcmd as new oledbcommand("select * from Users", conn)
>> dim objreader as oledbdatareader
>>
>> try
>> objcmd.connection.open()
>> objreader = objcmd.executereader()
>> catch ex as exception
>> lblMessage.text = "Error retrieving from the 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 as string)
>> 'open connection
>> 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><body>
>> <asp:Label id="lblMessage" runat="server"/>
>>
>> <form runat="server">
>> <asp:Datagrid id="dgData" runat="server"
>> BorderColor="Black" gridlines="vertical"
>> cellpadding="4" cellspacing="0" width="100%"
>> autogeneratecolumns="false"
>> ondeletecommand="dgData_Delete"
>> onEditcommand="dgData_Edit"
>> onCancelcommand="dgData_Cancel"
>> onUpdatecommand="dgData_Update"
>> onpageindexchanged="dgData_PageIndexChanged">
>>
>> <columns>
>> <asp:TemplateColumn headertext="ID">
>> <itemtemplate>
>> <asp:Label id="Name" text='<%#
>> container.dataitem("ID") %>' runat="server"/>
>> </itemtemplate>
>> </asp:templatecolumn>
>>
>> <asp:boundcolumn headertext="First Name"
>> datafield="FirstName"/>
>> <asp:boundcolumn headertext="Last Name"
>> datafield="LastName"/>
>> <asp:boundcolumn headertext="Address" datafield="Address"/>
>> <asp:boundcolumn headertext="City" datafield="City"/>
>> <asp:boundcolumn headertext="State" datafield="State"/>
>> <asp:boundcolumn headertext="Zip" datafield="Zip"/>
>> <asp:boundcolumn headertext="Phone" datafield="Phone"/>
>>
>> <asp:editcommandcolumn edittext="Edit" canceltext="Cancel"
>> updatetext="Update" headertext="Edit"/>
>> <asp:buttoncolumn headertext="" text="Delete"
>> commandname="Delete"/>
>> </columns>
>> </asp:datagrid><p>
>>
>> <asp:panel id="AddPanel" runat="server">
>> <table>
>> <tr>
>> <td width="100" valign="top">First and last name: </td>
>> <td width="300" valign="top">
>> <asp:textbox id="tbFName" runat="server"/>
>> <asp:textbox id="tbLName" runat="server"/>
>> </td>
>> </tr>
>>
>> <tr>
>> <td width="100" valign="top">Address: </td>
>> <td width="300" valign="top">
>> <asp:textbox id="tbAddress" runat="server"/>
>> </td>
>> </tr>
>>
>> <tr>
>> <td width="100" valign="top">City, State, Zip: </td>
>> <td width="300" valign="top">
>> <asp:textbox id="tbCity" runat="server"/>,
>> <asp:textbox id="tbState" size=2
>> runat="server"/>
>> <asp:textbox id="tbZip" size=5 runat="server"/>
>> </td>
>> </tr>
>>
>> <tr>
>> <td width="100" valign="top">Phone: </td>
>> <td width="300" valign="top">
>> <asp:textbox id="tbPhone" size=11 runat="server"/>
>> </td>
>> </tr>
>>
>> <tr>
>> <td colspan=2 valign="top" align="right">
>> <asp:Button id="btSubmit" text="Add" onclick="Submit"
>> runat="server"/>
>> </td>
>> </tr>
>> </table>
>> </asp:panel>
>> </form>
>> </body></html>
>>
Thanks for your response...I will go out and buy visual studio, I was
waiting until I finished reading this book, but I guess I should get it
sooner than that. I'm sorry for not being more clear...the error
occurs when the Submit button is clicked and it says "Error updating
the database", which is the error message in the Try-Catch block in the
ExecuteStatement function.
I am using an Access database with one table called Users and it has
the following fields:
FirstName
LastName
Address
City
State
Zip
Phone
Take out your try/catch and see what the exception is when it gets
thrown.
Also, don't buy Visual Studio. Either get hold of one of the express
versions, or write your code by hand. Drop notepad though, you can get
free trials of various programmer's editors (I use Ultra Edit studio
for everything), or even just use a freeware editor like notepad2 - you
just want to make sure you've got syntax highlighting, brace matching
etc. Writing code by hand takes longer, but it's the best way to learn
by a long long way.
Thanks for the help...I wound up getting it to work. Taking out the
try/catch block showed me the error "Must use Updatequery table", or
something of the like. I looked around and found that it was a
permissions issue on the folder containing the db!
it now works and i'm on my way with ASP.NET...i'll probably be back to
ask more questions when i get stuck!
Thanks again all!!!
Newbie help!
I am reading a book on ASP.NET and the following code is from the book
(Teach Yourself ASP.NET in 21 Days by Chris Payne). I have typed the
code in notepad and I am having a problem with it that I hope someone
can help. Basically there is a Submit button which is supposed to
update an Access database, but for some reason it keeps on erroring
out. I have it in a try-catch block and I cannot get the update or
delete to work without error. The following is the code from the book.
Thank you in advance for your help!!!
<%@dotnet.itags.org. Page language="VB" %>
<%@dotnet.itags.org. import namespace="system.data" %>
<%@dotnet.itags.org. import namespace="system.data.oledb" %>
<script runat="server">
'declare connection
dim conn as new oledbconnection("Provider=Microsoft.Jet.OLEDB.4.0;
Data source=C:\Inetpub\wwwroot\Day8\banking.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)
'insert new data
dim i, j as integer
dim params(7) 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 & "You forgot to add a
value for " & addpanel.controls(i).id & "<p>"
lblmessage.style("Forecolor") = "red"
end if
j = j + 1
end if
next i
if not blngo then
exit sub
end if
dim strsql as string = "INSERT INTO Users (FirstName, LastName,
Address, City, State, Zip, Phone) VALUES (" & _
"'" & params(0) & "'," & _
"'" & params(1) & "'," & _
"'" & params(2) & "'," & _
"'" & params(3) & "'," & _
"'" & params(4) & "'," & _
"'" & params(5) & "'," & _
"'" & params(6) & "')"
executestatement(strsql)
filldatagrid()
end sub
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 = "DELETE FROM Users WHERE ID = " & e.item.itemindex
executestatement(strsql)
filldatagrid()
end sub
sub dgdata_update(sender as object, e as datagridcommandeventargs)
if updatedatastore(e) then
filldatagrid(-1)
end if
end sub
sub dgdata_cancel(sender as object, e as datagridcommandeventargs)
filldatagrid(-1)
end sub
sub dgdata_pageindexchanged(sender as object, e as
datagridpagechangedeventargs)
dgdata.databind()
end sub
function updatedatastore(e as datagridcommandeventargs) as boolean
dim i,j as integer
dim params(7) as string
dim strtext as string
dim blnGo as boolean = true
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
else
blngo = false
lblmessage.text = lblmessage.text & "You forgot to enter a
value <p>"
end if
next i
if not blngo then
return false
exit function
end if
dim strsql as string = "UPDATE Users SET " & _
"FirstName = '" & params(0) & "'," & _
"LastName = '" & params(1) & "'," & _
"Address = '" & params(2) & "'," & _
"City = '" & params(3) & "'," & _
"State = '" & params(4) & "'," & _
"Zip = '" & params(5) & "'," & _
"Phone = '" & params(6) & "' " & _
"WHERE ID = " &
ctype(e.item.cells(0).controls(1),label).text
executestatement(strsql)
return blngo
end function
sub filldatagrid(optional editindex as integer = -1)
'open connection
dim objcmd as new oledbcommand("select * from Users", conn)
dim objreader as oledbdatareader
try
objcmd.connection.open()
objreader = objcmd.executereader()
catch ex as exception
lblMessage.text = "Error retrieving from the 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 as string)
'open connection
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><body>
<asp:Label id="lblMessage" runat="server"/>
<form runat="server">
<asp:Datagrid id="dgData" runat="server"
BorderColor="Black" gridlines="vertical"
cellpadding="4" cellspacing="0" width="100%"
autogeneratecolumns="false"
ondeletecommand="dgData_Delete"
onEditcommand="dgData_Edit"
onCancelcommand="dgData_Cancel"
onUpdatecommand="dgData_Update"
onpageindexchanged="dgData_PageIndexChanged">
<columns>
<asp:TemplateColumn headertext="ID">
<itemtemplate>
<asp:Label id="Name" text='<%#
container.dataitem("ID") %>' runat="server"/>
</itemtemplate>
</asp:templatecolumn>
<asp:boundcolumn headertext="First Name"
datafield="FirstName"/>
<asp:boundcolumn headertext="Last Name"
datafield="LastName"/>
<asp:boundcolumn headertext="Address" datafield="Address"/>
<asp:boundcolumn headertext="City" datafield="City"/>
<asp:boundcolumn headertext="State" datafield="State"/>
<asp:boundcolumn headertext="Zip" datafield="Zip"/>
<asp:boundcolumn headertext="Phone" datafield="Phone"/>
<asp:editcommandcolumn edittext="Edit" canceltext="Cancel"
updatetext="Update" headertext="Edit"/>
<asp:buttoncolumn headertext="" text="Delete"
commandname="Delete"/>
</columns>
</asp:datagrid><p>
<asp:panel id="AddPanel" runat="server">
<table>
<tr>
<td width="100" valign="top">First and last name: </td>
<td width="300" valign="top">
<asp:textbox id="tbFName" runat="server"/>
<asp:textbox id="tbLName" runat="server"/>
</td>
</tr>
<tr>
<td width="100" valign="top">Address: </td>
<td width="300" valign="top">
<asp:textbox id="tbAddress" runat="server"/>
</td>
</tr>
<tr>
<td width="100" valign="top">City, State, Zip: </td>
<td width="300" valign="top">
<asp:textbox id="tbCity" runat="server"/>,
<asp:textbox id="tbState" size=2
runat="server"/>
<asp:textbox id="tbZip" size=5 runat="server"/>
</td>
</tr>
<tr>
<td width="100" valign="top">Phone: </td>
<td width="300" valign="top">
<asp:textbox id="tbPhone" size=11 runat="server"/>
</td>
</tr>
<tr>
<td colspan=2 valign="top">
<asp:Button id="btSubmit" text="Add" onclick="Submit"
runat="server"/>
</td>
</tr>
</table>
</asp:panel>
</form>
</body></html>Two things. !
1.) Go and buy visual studio, you really wont go far using notepad (
Although you can get by without it, it will be a nightmare )
2.) You dont say what the error is.?
( OHM ) - One Handed Man
AKA Terry Burns - http://TrainingOn.net
<MPotok@.gmail.com> wrote in message
news:1145338918.804159.312510@.v46g2000cwv.googlegroups.com...
> Hi,
> I am reading a book on ASP.NET and the following code is from the book
> (Teach Yourself ASP.NET in 21 Days by Chris Payne). I have typed the
> code in notepad and I am having a problem with it that I hope someone
> can help. Basically there is a Submit button which is supposed to
> update an Access database, but for some reason it keeps on erroring
> out. I have it in a try-catch block and I cannot get the update or
> delete to work without error. The following is the code from the book.
> Thank you in advance for your help!!!
> <%@. Page language="VB" %>
> <%@. import namespace="system.data" %>
> <%@. import namespace="system.data.oledb" %>
> <script runat="server">
> 'declare connection
> dim conn as new oledbconnection("Provider=Microsoft.Jet.OLEDB.4.0;
> Data source=C:\Inetpub\wwwroot\Day8\banking.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)
> 'insert new data
> dim i, j as integer
> dim params(7) 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 & "You forgot to add a
> value for " & addpanel.controls(i).id & "<p>"
> lblmessage.style("Forecolor") = "red"
> end if
> j = j + 1
> end if
> next i
> if not blngo then
> exit sub
> end if
> dim strsql as string = "INSERT INTO Users (FirstName, LastName,
> Address, City, State, Zip, Phone) VALUES (" & _
> "'" & params(0) & "'," & _
> "'" & params(1) & "'," & _
> "'" & params(2) & "'," & _
> "'" & params(3) & "'," & _
> "'" & params(4) & "'," & _
> "'" & params(5) & "'," & _
> "'" & params(6) & "')"
> executestatement(strsql)
> filldatagrid()
> end sub
> 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 = "DELETE FROM Users WHERE ID = " & e.item.itemindex
> executestatement(strsql)
> filldatagrid()
> end sub
> sub dgdata_update(sender as object, e as datagridcommandeventargs)
> if updatedatastore(e) then
> filldatagrid(-1)
> end if
> end sub
> sub dgdata_cancel(sender as object, e as datagridcommandeventargs)
> filldatagrid(-1)
> end sub
> sub dgdata_pageindexchanged(sender as object, e as
> datagridpagechangedeventargs)
> dgdata.databind()
> end sub
> function updatedatastore(e as datagridcommandeventargs) as boolean
> dim i,j as integer
> dim params(7) as string
> dim strtext as string
> dim blnGo as boolean = true
> 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
> else
> blngo = false
> lblmessage.text = lblmessage.text & "You forgot to enter a
> value <p>"
> end if
> next i
> if not blngo then
> return false
> exit function
> end if
> dim strsql as string = "UPDATE Users SET " & _
> "FirstName = '" & params(0) & "'," & _
> "LastName = '" & params(1) & "'," & _
> "Address = '" & params(2) & "'," & _
> "City = '" & params(3) & "'," & _
> "State = '" & params(4) & "'," & _
> "Zip = '" & params(5) & "'," & _
> "Phone = '" & params(6) & "' " & _
> "WHERE ID = " &
> ctype(e.item.cells(0).controls(1),label).text
> executestatement(strsql)
> return blngo
> end function
> sub filldatagrid(optional editindex as integer = -1)
> 'open connection
> dim objcmd as new oledbcommand("select * from Users", conn)
> dim objreader as oledbdatareader
> try
> objcmd.connection.open()
> objreader = objcmd.executereader()
> catch ex as exception
> lblMessage.text = "Error retrieving from the 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 as string)
> 'open connection
> 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><body>
> <asp:Label id="lblMessage" runat="server"/>
> <form runat="server">
> <asp:Datagrid id="dgData" runat="server"
> BorderColor="Black" gridlines="vertical"
> cellpadding="4" cellspacing="0" width="100%"
> autogeneratecolumns="false"
> ondeletecommand="dgData_Delete"
> onEditcommand="dgData_Edit"
> onCancelcommand="dgData_Cancel"
> onUpdatecommand="dgData_Update"
> onpageindexchanged="dgData_PageIndexChanged">
> <columns>
> <asp:TemplateColumn headertext="ID">
> <itemtemplate>
> <asp:Label id="Name" text='<%#
> container.dataitem("ID") %>' runat="server"/>
> </itemtemplate>
> </asp:templatecolumn>
> <asp:boundcolumn headertext="First Name"
> datafield="FirstName"/>
> <asp:boundcolumn headertext="Last Name"
> datafield="LastName"/>
> <asp:boundcolumn headertext="Address" datafield="Address"/>
> <asp:boundcolumn headertext="City" datafield="City"/>
> <asp:boundcolumn headertext="State" datafield="State"/>
> <asp:boundcolumn headertext="Zip" datafield="Zip"/>
> <asp:boundcolumn headertext="Phone" datafield="Phone"/>
> <asp:editcommandcolumn edittext="Edit" canceltext="Cancel"
> updatetext="Update" headertext="Edit"/>
> <asp:buttoncolumn headertext="" text="Delete"
> commandname="Delete"/>
> </columns>
> </asp:datagrid><p>
> <asp:panel id="AddPanel" runat="server">
> <table>
> <tr>
> <td width="100" valign="top">First and last name: </td>
> <td width="300" valign="top">
> <asp:textbox id="tbFName" runat="server"/>
> <asp:textbox id="tbLName" runat="server"/>
> </td>
> </tr>
> <tr>
> <td width="100" valign="top">Address: </td>
> <td width="300" valign="top">
> <asp:textbox id="tbAddress" runat="server"/>
> </td>
> </tr>
> <tr>
> <td width="100" valign="top">City, State, Zip: </td>
> <td width="300" valign="top">
> <asp:textbox id="tbCity" runat="server"/>,
> <asp:textbox id="tbState" size=2
> runat="server"/>
> <asp:textbox id="tbZip" size=5 runat="server"/>
> </td>
> </tr>
> <tr>
> <td width="100" valign="top">Phone: </td>
> <td width="300" valign="top">
> <asp:textbox id="tbPhone" size=11 runat="server"/>
> </td>
> </tr>
> <tr>
> <td colspan=2 valign="top">
> <asp:Button id="btSubmit" text="Add" onclick="Submit"
> runat="server"/>
> </td>
> </tr>
> </table>
> </asp:panel>
> </form>
> </body></html>
>
Or download VWD Express Edition for free (For a year anyway). I've been
using it a few w
built a great KPI dashboard for work which updates continuously throughout
the day...really productive
http://msdn.microsoft.com/vstudio/express/vwd/
HTH
Nick Hodge
Microsoft MVP - Excel
Southampton, England
www.nickhodge.co.uk
nick_hodgeTAKETHISOUT@.zen.co.uk.ANDTHIS
"OHM ( One Handed Man )" <me@.mine.com> wrote in message
news:uKLso9qYGHA.4620@.TK2MSFTNGP04.phx.gbl...
> Two things. !
> 1.) Go and buy visual studio, you really wont go far using notepad (
> Although you can get by without it, it will be a nightmare )
> 2.) You dont say what the error is.?
> --
> ( OHM ) - One Handed Man
> AKA Terry Burns - http://TrainingOn.net
>
> <MPotok@.gmail.com> wrote in message
> news:1145338918.804159.312510@.v46g2000cwv.googlegroups.com...
>
Thanks for your response...I will go out and buy visual studio, I was
waiting until I finished reading this book, but I guess I should get it
sooner than that. I'm sorry for not being more clear...the error
occurs when the Submit button is clicked and it says "Error updating
the database", which is the error message in the Try-Catch block in the
ExecuteStatement function.
I am using an Access database with one table called Users and it has
the following fields:
FirstName
LastName
Address
City
State
Zip
Phone
Take out your try/catch and see what the exception is when it gets
thrown.
Also, don't buy Visual Studio. Either get hold of one of the express
versions, or write your code by hand. Drop notepad though, you can get
free trials of various programmer's editors (I use Ultra Edit studio
for everything), or even just use a freeware editor like notepad2 - you
just want to make sure you've got syntax highlighting, brace matching
etc. Writing code by hand takes longer, but it's the best way to learn
by a long long way.
Thanks for the help...I wound up getting it to work. Taking out the
try/catch block showed me the error "Must use Updatequery table", or
something of the like. I looked around and found that it was a
permissions issue on the folder containing the db!
it now works and i'm on my way with ASP.NET...i'll probably be back to
ask more questions when i get stuck!
Thanks again all!!!
Thursday, March 22, 2012
newbie issue
I'm new to the concept of ASP programming but still "I'm not ignorant"...
I was working on a guest book, I've done everything, but I don't know how to save content of a textbox into file (Append).
P.S.
1- I'm using ASP .NET 2 VS 2005
2- The programming language is not a problem
Thanks in advancehttp://support.microsoft.com/default.aspx?scid=kb;EN-US;816149
But for a guestbook, why not use a database? Files are rather inefficient, but hey, it's your website.
http://support.microsoft.com/default.aspx?scid=kb;EN-US;816149
But for a guestbook, why not use a database? Files are rather inefficient, but hey, it's your website.
The site doesn't contain anything about ASP
1. ASP.NET isn't a programming language, it is a technology. You still use a codebehind language such as VB.NET or C#.
2. The syntax will be just about the same for you in 2.0.
3. If you are viewing that page in Firefox, it is broken. Scroll down until you see the floating islands of code.
1. ASP.NET isn't a programming language, it is a technology. You still use a codebehind language such as VB.NET or C#.
I knew someone is gonna say that, so I said "I'm not ignorant" :p
2. The syntax will be just about the same for you in 2.0.
I don't understand what does this mean!
3. If you are viewing that page in Firefox, it is broken. Scroll down until you see the floating islands of code.
I'm using FF and I saw the code (what's a floating island? :confused: )
My problem is "I know how to write to a file, but how can I use a file in one of my web folders?"
Use a file... can you explain that?
It's very simple, I have a file that I use for read-write... (It contains Guests messages to read & new messages are appended to it)
The thing is, in what path should I store it so I can read from it and write to it without getting the "Access Denied" Exception
In regular VB I use the property Application.WorkingDirectory to get the current path, is there an equivalent in ASP?
Ideally, should be the same path as the asp.net application.
Use Server.Mappath().