I am getting view state errors on this page. Not very frequent but I still see them here. I think my sql statement it to blame for this. Can anyon help me figure out whats wrong or maybe help me produce a better statement?
<%@ Page Language=VB Debug=true %>
<%@ Import Namespace="System.Data" %>
<%@ Import Namespace="System.Data.OLEDB" %>
<script runat="server">
Sub SubmitBtn_Click(Sender As Object, E As EventArgs)
Dim DBConn as OleDbConnection
Dim DBCommand As OleDbDataAdapter
Dim DSLogin as New DataSet
DBConn = New OleDbConnection("PROVIDER=Microsoft.Jet.OLEDB.4.0;" _
& "DATA SOURCE=" _
& Server.MapPath("/knightsempire/db/members/" _
& "members.mdb;"))
DBCommand = New OleDbDataAdapter _
("Select MemberID from " _
& "Members Where " _
& "MemName = '" & txtMemberName.Text _
& "' and Password = '" & txtPassword.Text _
& "'", DBConn)
DBCommand.Fill(DSLogin, _
"MemberInfo")
If DSLogin.Tables("MemberInfo"). _
Rows.Count = 0 Then
lblMessage.Text = "Invalid name or password"
Else
session("memname")=txtmembername.text
Session("MemberID") = DSLogin.Tables("MemberInfo"). _
Rows(0).Item("MemberID")
Response.Redirect("http://www12.brinkster.com/knightsempire/db/members/loggedin.aspx")
End If
End Sub
</SCRIPT>
<HTML>
<HEAD>
<TITLE>Log In</TITLE>
</HEAD>
<BODY bgcolor="000000" TEXT="4682b4" LINK="00ffff" VLINK="00ffff" ALINK="00ffff">
<!--
function MM_openBrWindow(theURL,winName,features) { //v2.0
window.open(theURL,winName,features);
}
//-->
</script>
hi,
you have an extra script tag to start with, will post again soon:
<%@ Page Language=VB Debug=true %>
<%@ Import Namespace="System.Data" %>
<%@ Import Namespace="System.Data.OLEDB" %>
<script runat="server">
Sub SubmitBtn_Click(Sender As Object, E As EventArgs)
Dim DBConn as OleDbConnection
Dim DBCommand As OleDbDataAdapter
Dim DSLogin as New DataSet
DBConn = New OleDbConnection("PROVIDER=Microsoft.Jet.OLEDB.4.0;" _
& "DATA SOURCE=" _
& Server.MapPath("/knightsempire/db/members/" _
& "members.mdb;"))
DBCommand = New OleDbDataAdapter _
("Select MemberID from " _
& "Members Where " _
& "MemName = '" & txtMemberName.Text _
& "' and Password = '" & txtPassword.Text _
& "'", DBConn)
DBCommand.Fill(DSLogin, _
"MemberInfo")
If DSLogin.Tables("MemberInfo"). _
Rows.Count = 0 Then
lblMessage.Text = "Invalid name or password"
Else
session("memname")=txtmembername.text
Session("MemberID") = DSLogin.Tables("MemberInfo"). _
Rows(0).Item("MemberID")
Response.Redirect("http://www12.brinkster.com/knightsempire/db/members/loggedin.aspx")
End If
End Sub
</SCRIPT>
<HTML>
<HEAD>
<TITLE>Log In</TITLE>
</HEAD>
<BODY bgcolor="000000" TEXT="4682b4" LINK="00ffff" VLINK="00ffff" ALINK="00ffff">
<!--
function MM_openBrWindow(theURL,winName,features) { //v2.0
window.open(theURL,winName,features);
}
//-->
</script>
hi,
give this a try, i coudn't test it so i hopes is ok:
<script runat="server">
Sub SubmitBtn_Click(Sender As Object, E As EventArgs)
Dim DBConn as OleDbConnection
Dim DBCommand As OleDbDataAdapter
Dim DSLogin as New DataSet
DBConn = New OleDbConnection("PROVIDER=Microsoft.Jet.OLEDB.4.0;" _
& "DATA SOURCE=" _
& Server.MapPath("/knightsempire/db/members/" _
& "members.mdb;"))
Dim CmdStr As String
Dim DBSelect As New OleDbCommand
CmdStr =("Select MemberID from Members Where MemName = @MemberName and Password = @Password ")
DBSelect = new OleDbCommand(CmdStr, DBconn)
DBSelect.Parameters.Add("@MemberName", OleDbType.VarChar, 255)
DBSelect.Parameters.Add("@Password", OleDbType.VarChar, 255)
compilation error, dbselect.fill is hylighted error says fill is not a data member or something like that
Ribeyed
03-01-2003, 12:04 PM
hi,
ok change this:
DBSelect.Fill(DSLogin, "MemberInfo")
to this:
DBCommand.Fill(DSLogin, "MemberInfo")
PeOfEo
03-01-2003, 12:11 PM
That seems to work. I have not seen any of my notorious 500 errors yet but hopefully they will not show their evil heads. But on the register form.... I just got a 500 error. Its not frequent at all anymore but every so often i still get one. I am not very worried about it anymore because user can come back in 2 minuits and reregister and it works again. About the web.config, how can I do it without a global.asax?
PeOfEo
03-01-2003, 12:13 PM
another error, I confirmed that this new script fixed ( i think it has) my 500 error but now I have this error message when the command button is clicked
Object reference not set to an instance of an object
Line 22: DBCommand.Fill(DSLogin, "MemberInfo")
PeOfEo
03-01-2003, 04:51 PM
Server Error in '/' Application.
--------------------------------------------------------------------------------
Object reference not set to an instance of an object.
Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code.
Exception Details: System.NullReferenceException: Object reference not set to an instance of an object.
Source Error:
Line 20: DBSelect.Parameters("@MemberName").Value = Replace(txtMemberName.text, "'", "''")
Line 21: DBSelect.Parameters("@Password").Value = Replace(txtPassword.text, "'", "''")
Line 22: DBCommand.Fill(DSLogin, _
Line 23: "MemberInfo")
Line 24:
PeOfEo
03-01-2003, 05:16 PM
why do you use a string?
DBCommand = New OleDbDataAdapter _
("Select MemberID from " _
& "Members Where " _
& "MemName = '" & txtMemberName.Text _
& "' and Password = '" & txtPassword.Text _
& "'", DBConn)
DBCommand.Fill(DSLogin, _
"MemberInfo")
whats wrong with that code? Thats what I had before, why are you convirting it to cmdstr?
Ribeyed
03-02-2003, 04:28 PM
hi Nick,
give this a try, sorry :),
CmdStr =("Select MemberID from Members Where MemName = @MemberName and Password = @Password ")
DBCommand = new SQlDataAdapter(CmdStr, DBconn)
DBCommand.Parameters.Add("@MemberName", OleDbType.VarChar, 255)
DBCommand.Parameters.Add("@Password", OleDbType.VarChar, 255)
sqldataadapter does not work. Why exactly do we do it this way and not like the code I was using before? Because It seemed to work some of the time. The errors were completly random. Why cant we just figure out what is causing the errors in my old syntax? It seems like it would be easyer to just do that then to rewrite the code. Is my old syntax just completly wrong?
Ribeyed
03-03-2003, 05:22 PM
hi,
ok sorry again should be OleDbDataAdapter. IF no joy give me a few days and i'll set this up on my machine test it then post you working code :(
PeOfEo
03-03-2003, 05:33 PM
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: BC30456: 'Parameters' is not a member of 'System.Data.OleDb.OleDbDataAdapter'.
Source Error:
Line 14: CmdStr =("Select MemberID from Members Where MemName = @MemberName and Password = @Password ")
Line 15: DBCommand = New OleDbDataAdapter (CmdStr, DBconn)
Line 16: DBCommand.Parameters.Add("@MemberName", OleDbType.VarChar, 255)
Line 17: DBCommand.Parameters.Add("@Password", OleDbType.VarChar, 255)
Line 18:
I tried that code earlyer :( But then I get that error. This might work but that would mean changing this code to something like what i had before I think. Can you think of an alternative? I know my vb6 code pretty well, Its these darned sql statements that are causing problems, Ill find a good tutorial site wrather then buying another book. Books get pricy when you by a bunch of em like me :D . Go to http://www12.brinkster.com/knightsempire/db/members/login.aspx . Thats where you can see my actualy error message
PeOfEo
03-03-2003, 05:37 PM
see how it says parameters is not a member. What would be the ole equivilant to paramets. I think if we figure this out, which I think we are close to doing, a lot of my future applications will run insanely smoothly. Also I am having a friend burn me dream weaver. Another friend says I should check out asp.net matrix, I think that was the name but it is supposed to be a good editor because it simulates a server when you edit your stuff. You can just change the server path when you upload your files
Ribeyed
03-03-2003, 05:57 PM
ok m8 i know were on the right track. I am correct in using the parameter object for submitting parameters to the query string. The problem is the connecting the connection object to the connection string, then connecting the datareader to the command and the command to the dataadapter, then the dataAdapter to the DataSet.
I am not saying that your way will not work for the sql statement but that way is not the prefered way. There is an object called parameters which is used for submitting parameters to query strings so i feel this is the way to go.
hi Nick,
give this a go it compiles without errors on my machine. Can't test against database because i don't have your database for this one. Let me know how it goes.
<script runat="server">
Sub SubmitBtn_Click(Sender As Object, E As EventArgs)
Dim DBConn as OleDbConnection
Dim DBCommand As OleDbDataAdapter
Dim DSLogin as New DataSet
DBConn = New OleDbConnection("PROVIDER=Microsoft.Jet.OLEDB.4.0;" _
& "DATA SOURCE=" _
& Server.MapPath("members.mdb;"))
Dim CmdStr As String
Dim DBSelect As New OleDbCommand
CmdStr =("Select MemberID from Members Where MemName = @MemberName and Password = @Password ")
DBSelect = new OleDbCommand(CmdStr, DBconn)
DBSelect.Parameters.Add("@MemberName", OleDbType.VarChar, 255)
DBSelect.Parameters.Add("@Password", OleDbType.VarChar, 255)
If DSLogin.Tables("MemberInfo"). _
Rows.Count = 0 Then
lblMessage.Text = "Invalid name or password"
Else
session("memname")=txtmembername.text
Session("MemberID") = DSLogin.Tables("MemberInfo"). _
Rows(0).Item("MemberID")
Response.Redirect("http://www12.brinkster.com/knightsempire/db/members/loggedin.aspx")
End If
End Sub
</SCRIPT>
PeOfEo
03-04-2003, 05:01 PM
Server Error in '/' Application.
--------------------------------------------------------------------------------
Object reference not set to an instance of an object.
Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code.
Exception Details: System.NullReferenceException: Object reference not set to an instance of an object.
Source Error:
Line 20: DBSelect.Parameters("@Password").Value = Replace(txtPassword.text, "'", "''")
Line 21:
Line 22: DBCommand.Fill(DSLogin, _
Line 23: "MemberInfo")
Line 24:
These things bug me. Ok its not fining an object or variable somewhere in the code. I seem to get the exact same error on other pages too. Were should I look in my code to dig it out? I changed the data base path so that isn't the problem.
Ribeyed
03-04-2003, 08:55 PM
hi Nick,
here is working code, i have tried and tested this and it works. I know there is some changes again but i think i have cracked it so here it is:
<script runat="server">
Sub SubmitBtn_Click(Sender As Object, E As EventArgs)
Dim DBConn as OleDbConnection
Dim dtrResults as OleDBDataReader
Dim DSLogin as New DataSet
DBConn = New OleDbConnection("PROVIDER=Microsoft.Jet.OLEDB.4.0;" _
& "DATA SOURCE=" _
& Server.MapPath("members.mdb;"))
DBConn.Open()
Dim CmdStr As String
Dim DBSelect As New OleDbCommand
CmdStr =("Select MemberID from Members Where MemName = @MemberName and Password = @Password ")
DBSelect = new OleDbCommand(CmdStr, DBconn)
DBSelect.Parameters.Add("@MemberName", OleDbType.VarChar, 255)
DBSelect.Parameters.Add("@Password", OleDbType.VarChar, 255)
DBSelect.Parameters("@MemberName").Value = txtMemberName.text
DBSelect.Parameters("@Password").Value = txtPassword.text
dtrResults = DBSelect.ExecuteReader()
if dtrResults.Read()
session("memname") = txtmembername.text
session("memberID") = dtrResults("MemberID")
Response.Redirect("http://www12.brinkster.com/knightsempire/db/members/loggedin.aspx")
else
response.write("sorry not this time!")
end if
DBConn.Close()
End Sub
</SCRIPT>
PeOfEo
03-04-2003, 10:07 PM
IT SEEMS TO WORK NOW! Thank you so much for this help you have provided. Next order of buisiness, my registration page still seems to have 500's in it. They are not very frequent but I still get them. You said I still had some syntax I needed to change. What syntax, like where? Ill post my complete code for this page below
PeOfEo
03-04-2003, 10:10 PM
<%@ Page Language="VB" Debug="true" %>
<%@ Import Namespace="System.Data" %>
<%@ Import Namespace="System.Data.OLEDB" %>
<script runat="server">
Sub SubmitBtn_Click(Sender As Object, E As EventArgs)
if txtrank.selecteditem.value = "Peasent" then
lblrnkval.text="1"
end if
if txtrank.selecteditem.value = "Soldier" then
lblrnkval.text="2"
end if
if txtrank.selecteditem.value = "Page" then
lblrnkval.text="3"
end if
if txtrank.selecteditem.value = "Guard" then
lblrnkval.text="4"
end if
if txtrank.selecteditem.value = "Knight" then
lblrnkval.text="5"
end if
if txtrank.selecteditem.value = "Elite" then
lblrnkval.text="6"
end if
if txtrank.selecteditem.value = "Lord" then
lblrnkval.text="7"
end if
if txtrank.selecteditem.value = "Preist" then
lblrnkval.text="8"
end if
if txtrank.selecteditem.value = "Paladin" then
lblrnkval.text="9"
end if
if txtrank.selecteditem.value = "Apprentice" then
lblrnkval.text="10"
end if
if txtrank.selecteditem.value = "Noble" then
lblrnkval.text="11"
end if
Dim CmdStr As String
Dim DBConn as OleDbConnection
Dim DBCommand As OleDbDataAdapter
Dim DSLogin as New DataSet
Dim DBInsert As New OleDbCommand
DBConn = New OleDbConnection("PROVIDER=Microsoft.Jet.OLEDB.4.0;" _
& "DATA SOURCE=" _
& Server.MapPath("/knightsempire/db/members/" _
& "members.mdb;"))
DBCommand = New OleDbDataAdapter _
("Select Count(MemberID) as TheCount " _
& "from Members Where " _
& "MemName = '" & txtMemberName.Text _
& "'", DBConn)
DBCommand.Fill(DSLogin, _
"TheCount")
If DSLogin.Tables("TheCount").Rows(0).Item("TheCount") = 0 Then
DBCommand = New OleDbDataAdapter _
("Select MemberID from Members Where " _
& "MemberName = '" & txtMemberName.Text _
& "' and Password = '" & txtPassword.Text _
& "'", DBConn)
Response.Redirect("./list.aspx")
Else
lblMessage.Text = "The member name you entered is in " _
& "use by another member. Please enter " _
& "another member name."
End If
End Sub
</SCRIPT>
<HTML>
<HEAD>
<TITLE>Register</TITLE>
</HEAD>
<BODY BACKGROUND="http://www12.brinkster.com/knightsempire/tilehdark.jpg" TEXT="4682b4" LINK="00ffff" VLINK="00ffff" ALINK="00ffff" LEFTMARGIN="40">