Thursday, March 22, 2012

why there is error in line 79

can someone tell me wats the error in line 79? how can i debug it
Compilation Error
Description: An error occurred during the compilation of a resource required to service this request. Please review the following specific error details and modify your source code appropriately.

Compiler Error Message: BC30455: Argument not specified for parameter 'e' of 'Public Function updatedatastore(e As System.Web.UI.WebControls.DataGridCommandEventArgs) As Boolean'.

Source Error:

Line 77:
Line 78: sub dgdata_update (sender as object, e as datagridcommandeventargs)
(error) Line 79: if updatedatastore then
Line 80: filldatagrid(-1)
Line 81: end if

<%@dotnet.itags.org. Page Language = "vb" Debug="true" %>
<%@dotnet.itags.org. import namespace= "system.data" %>
<%@dotnet.itags.org. import namespace= "system.data.oledb" %>
<script runat="server"
'set up connection
dim conn as new oledbconnection _
("provider = microsoft.jet.oledb.4.0;" & _
"data source = c:\aspnet\data\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 enter a value for " & _
addpanel.controls (i).id & "<p>"
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 tblusers " & _
"(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 as string = "DELETE FROM tblusers " & _
"WHERE userid = " & e.item.itemindex + 1

executestatement(strsql)

filldatagrid()
end sub

sub dgdata_update (sender as object, e as datagridcommandeventargs)

' ERROR line 79 anyone know why, how to solve it?
if updatedatastore 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
j= j+1
else
blngo = false
lblmessage.text = lblmessage.text & _
"you forgot to enter a value<p>"
end if
next

if not blngo then
return false
exit function
end if

dim strsql as string = "update tblusers SET " & _
"Firstname = '" & params(0) & "'," & _
"lastname = '" & params(1) & "'," & _
"address = '" & params(2) & "'," & _
"city = '" & params(3) & "'," & _
"state = '" & params(4) & "'," & _
"zip = '" & params(5) & "'," & _
"phone = '" & params(6) & "'," & _
" WHERE Userid = " & 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 tblusers", 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)
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"
font-names = "arial"
font-size="8pt"
showfooter = "true"
headerstyle-backcolor= "#cccc99"
footerstyle-backcolor= "#cccc99"
itemstyle-backcolor= "#ffffff"
alternatingitemstyle-backcolor="#cccccc"
<columns>
<asp:templatecolumn headertext="id">
<itemtemplate>
<asp:label id = "name" runat = "server"
text = '<%# container.dataitem("userid")%>' />
</itemtemplate>
</asp:templatecolumn
<asp:boundcolumn headertext = "firstname"
datafield = "firstname" /
<asp:boundcolumn headertext = "lastname"
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 = "delete?" text = "X"
commandname = "delete"
buttontype = "pushbutton" /
</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 valign = "top">address:</td>
<td valign= "top">
<asp:textbox id= "tbaddress" runat = "server"/>
</td>
</tr>
<tr>
<td valign = "top">city, state, zip:</td>
<td valign= "top">
<asp:textbox id= "tbcity" runat = "server"/>
<asp:textbox id= "tbstate" runat = "server"/>
<asp:textbox id= "tbzip" runat = "server"
size=5 />
</td>
</tr>
<tr>
<td valign= "top">phone:</td>
<td valign= "top">
<asp:textbox id= "tbphone" runat = "server"
size = 11/><p>
</td>
</tr>
<tr>
<td colspan = "2" valign = "top" allign = "right">
<asp:button id = "btsubmit" runat ="server" text ="add"
onclick = "submit" />
</td>
</tr>
</table>
</asp:panel>
</form>
</body></html>Yourupdatedatastore method requires a DataGridCommandEventArgs Object to passed as a parameter (as the Compiler Error Message states). Amend your code to read:

 if updatedatastore(e) then

BUt why mydatabase isn't updating the new information that i type in as well as in the webpage also?
The problem is your logic. If any of the Textboxes have an empty value then the return value will be set to false, however if a following Textbox does have a value then the return value remains false. Add the line in bold:
 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
blngo = true
j= j+1

else

blngo = false
lblmessage.text = lblmessage.text & "you forgot to enter a value<p>"

end if

next

if not blngo then

return false

end if

dim strsql as string = "update tblusers SET " & _
"Firstname = '" & params(0) & "'," & _
"lastname = '" & params(1) & "'," & _
"address = '" & params(2) & "'," & _
"city = '" & params(3) & "'," & _
"state = '" & params(4) & "'," & _
"zip = '" & params(5) & "'," & _
"phone = '" & params(6) & "'," & _
" WHERE Userid = " & ctype(e.item.cells(0). _
controls(1), label).text

executestatement (strsql)

return blngo

end function


Sorry, stev.
my database is still not updating i receive an error (error updating the database. )

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

'how can i fix it?
If you have got an error, pls give the error msg. If u have nt got any error, then i suppose it did not find the corresponding record in the database. Just keep a breakpoint and watch the sqlstatement. Verify whether the user id is in the table. I hope it will help u. Do write.
I'm just a beginer, can you please show me how to do it.?thanks

 lblmessage.text = ex.Message

It show me an error (syntax) how could i fix it. The error in within the update statement.
How could i fox it in order to have my database update?
Unless you post something to fix (i.e. the error message and the appropriate code - if you haven't posted it already), then I'm afraid the answer is I don't know.
You should do a research on "Sql Injection Attack" because your code is wide open to that.

0 comments:

Post a Comment