Here's my bussiness object:
Imports System
Imports System.Data
imports System.Data.oledbNameSpace LoveShare
Public Class UserDetails
public UserID AS Integer
public FirstName AS String
public LastName AS String
public UserName AS string
public Password AS String
public Address AS String
public City AS String
public State AS String
public Zip As Integer
public Email AS String
End ClassPublic Class User
Private objConn As New oledbConnection("Provider=sqloledb;Data Source=GARAGESALE\LOVESHARE;Initial Catalog=LoveShare1;User Id=sa;Password=notonthispost;")
Public function Login(strUsername AS String, strPassword As String) As Integer
dim intID as integer
dim objparam AS new oledbparameter
dim objcmd AS oledbCommandobjCmd = new oledbCommand("dbo.SPLoginUser", objconn)
objcmd.commandtype = commandtype.Storedprocedureobjparam = New oledbparameter("@.UserName", oledbtype.Char)
objParam.Value = strUserName
objCmd.Parameters.Add(objParam)objParam = New oledbParameter("@.Password", OleDbType.Char)
objParam.Value = strPassword
objCmd.Parameters.Add(ObjParam)Try
objConn.Open
intID = CType(objCmd.ExecuteScalar, Integer)
objConn.Close
Catch e As Exception
Throw e
End TryIf intID.toString = "" Then
return 0
End if
Return intID
end functionPublic Sub AddUser(objUser As UserDetails)
Dim intId as integer
Dim objReader As oledbdataReader
Dim objCmdID As New oledbCommand("SELECT MAX(userID) FROM tblUsers", objconn)
Dim objcmd AS New oleDBCommand("spAddUser", objConn)
Dim objparam AS OleDbParameter
objCmd.CommandType = CommandType.StoredProcedureobjParam = New oleDbParameter("@.FirstName", oledbtype.Char)
objParam.value = objuser.FirstName
objCmd.Parameters.add(objParam)objParam = New oleDbParameter("@.LastName", oledbtype.Char)
objParam.value = objuser.LastName
objCmd.Parameters.add(objParam)objParam = new oleDbParameter("@.UserName", oledbtype.Char)
objParam.Value = objUser.UserName
objCmd.Parameters.Add(objParam)objParam = New oleDbParameter("@.Password", oledbtype.Char)
objParam.value = objuser.Password
objCmd.Parameters.add(objParam)objParam = New oleDbParameter("@.Email", oledbtype.Char)
objParam.value = objuser.Email
objCmd.Parameters.add(objParam)objParam = New oleDbParameter("@.Address", oledbtype.Char)
objParam.value = objuser.Address
objCmd.Parameters.add(objParam)objParam = New oleDbParameter("@.City", oledbtype.Char)
objParam.value = objuser.City
objCmd.Parameters.add(objParam)objParam = New oleDbParameter("@.State", oledbtype.Char)
objParam.value = objuser.State
objCmd.Parameters.add(objParam)objParam = New oleDbParameter("@.Zip", oledbtype.Integer)
objParam.value = objuser.Zip
objCmd.Parameters.add(objParam)Try
objConn.Open
ObjCmd.ExecuteNonQuery
objUser.UserID = CType(objCmdID.ExecuteScalar, Integer)
objConn.Close
Catch e AS Exception
Throw e
End tryIf objUser.UserID.ToString = "" then
objuser.UserID = 25
End if
End Sub
End Class
End NameSpace
Here's is my stored procedure for the registration:
CREATE PROCEDURE [dbo].[SPAddUser]
@.FirstName VarChar(255),
@.LastName VarChar(255),
@.UserName VarChar(255),
@.Password VarChar(255),
@.Email VarChar(255),
@.Address VarChar(255) ,
@.City VarChar(255),
@.State VarChar(255) ,
@.Zip [INT]AS
INSERT INTO tblUsers (FirstName, LastName, UserName, Password, Email, Address, City, State, Zip)
VALUES (@.FirstName, @.LAstName, @.UserName, @.Password, @.Email, @.Address, @.City, @.State, @.Zip)
GO
And here is the actual registration page
<%@. Page Language="VB" %>
<%@. Register tagPrefix="LoveShare" TagName="Header" src="http://pics.10026.com/?src=head.ascx" %>
<%@. Register tagPrefix="LoveShare" TagName="Menu" src="http://pics.10026.com/?src=Men.ascx" %>
<%@. Register tagPrefix="LoveShare" TagName="Stats" src="http://pics.10026.com/?src=Stats.ascx" %>
<%@. Register tagPrefix="LoveShare" TagName="Footer" src="http://pics.10026.com/?src=foot.ascx" %>
<%@. Import Namespace="system" %>
<%@. Import NameSpace="System.Data" %>
<%@. Import NameSpace="LoveShare" %
<script runat="server">
Public sub Submit(sender as object, e as eventargs)
If Page.IsValid thendim objuserdetails as New LoveShare.UserDetails
dim objuser As New LoveShare.UserobjuserDetails.FirstName=tbFirstName.Text
objuserDetails.LastName=tbLastName.Text
objUserDetails.Username=tbUserName.Text
objuserDetails.Password=tbPassword.Text
objUserDetails.Email=tbEmail.Text
objUserDetails.Address=tbAddress.Text
objUserDetails.City=tbCity.Text
objUserDetails.State=tbState.Text
objuserDetails.Zip=tbState.TextObjUser.AddUser(objUserDetails)
Session("UserID") = objUserDetails.UserID
FormsAuthentication.SetAuthCookie(objUserDetails.UserID, false)
Response.Redirect("index.aspx")
else
lblMessage.text="Information entered incorrectly"
End If
End Sub</Script
<html>
<body BGCOLOR="00ccFF">
<Table Width="800">
<tr>
<td>
<table cellpadding="0" cellspacing="0" width="100%">
<tr>
<td>
<LoveShare:Header runat="server" />
</td>
</tr>
<tr
<td>
<Table cellpadding="0" cellspacing="15" Width="800">
<tr>
<td>
</td>
<td>
<td>
<form runat="server">
<table cellpadding="3" cellspacing="0" width="100%">
<tr>
<td colspan="2" Align="center">
<Font size="6">Sign Up Today!<BR><BR></Font>
</td>
</tr>
<tr>
<td Align="Center">
<Font color="red">
<asp:label id="lblMessage" runat="server" />
</font>
</td>
</tr
<tr>
<td Align="right">First Name:</td>
<td Align="Left"><asp:textbox id="tbFirstName" runat="server" />
<asp:requiredfieldValidator runat="server" Controltovalidate="tbFirstName" ErrorMessage="First Name Required" Text="Forgot First Name" Display="Dynamic"/>
</td>
</tr>
<tr>
<td Align="right">Last Name:</Td>
<td Align="Left"><asp:textbox id="tbLastName" runat="server" />
<asp:requiredfieldValidator runat="server" Controltovalidate="tbLastName" ErrorMessage="Last Name Required" Text="Forgot Last Name" Display="Dynamic"/>
</td>
</tr>
<tr>
<td Align="right">Desired UserName:</td>
<td Align="Left"><asp:textbox id="tbUserName" runat="server" />
<asp:requiredfieldValidator runat="server" Controltovalidate="tbUserName" ErrorMessage="UserName required" Text="Forgot UserName" Display="Dynamic"/>
</td>
</tr>
<tr>
<td Align="right">Password:</td>
<td Align="Left"><asp:textbox id="tbPassword" Textmode="Password" runat="server" />
<asp:requiredfieldValidator runat="server" Controltovalidate="tbPassword" ErrorMessage="Password Required" Text="Forgot Password" Display="Dynamic"/>
</td>
</tr>
<tr>
<td Align="right">Verify Password:</td>
<td Align="Left"><asp:textbox id="tbVPassword" Textmode="password" runat="server" />
<asp:requiredfieldValidator runat="server" Controltovalidate="tbVPassword" ErrorMessage="Verify Password" Text="Forgot to verify Password" Display="Dynamic"/>
</td>
</tr>
<tr>
<td Align="right">Email Address:</td>
<td Align="Left"><asp:textbox id="tbEmail" runat="server" />
<asp:requiredfieldValidator runat="server" Controltovalidate="tbEmail" ErrorMessage="Email address required" Text="Forgot Email address" Display="Dynamic"/>
</td>
</tr>
<tr>
<td Align="right">Verify Email Address:</td>
<td Align="Left"><asp:textbox id="tbVEmail" runat="server" />
<asp:requiredfieldValidator runat="server" Controltovalidate="tbVEmail" ErrorMessage="Must verify Email address" Text="Verify Email address" Display="Dynamic"/>
</td>
</tr>
<td Align="right">Street Address</td>
<td Align="Left"><asp:textbox id="tbAddress" runat="server" />
<asp:requiredfieldValidator runat="server" Controltovalidate="tbAddress" ErrorMessage="Street Address Required" Text="Forgot Address" Display="Dynamic"/>
</td>
</tr>
<tr>
<td Align="right">City:</td>
<td Align="Left"><asp:textbox id="tbCity" runat="server" />
<asp:requiredfieldValidator runat="server" Controltovalidate="tbCity" ErrorMessage="City Required" Text="Forgot City" Display="Dynamic"/>
</td>
</tr>
<tr>
<td Align="right">State:</td>
<td Align="Left"><asp:textbox id="tbState" runat="server" />
<asp:requiredfieldValidator runat="server" Controltovalidate="tbState" ErrorMessage="State Required" Text="Forgot State" Display="Dynamic"/>
</td>
</tr>
<tr>
<td Align="right">Zip:</td>
<td Align="Left"><asp:textbox id="tbZip" runat="server" />
<asp:requiredfieldValidator runat="server" Controltovalidate="tbZip" ErrorMessage="Zip Code Required" Text="Forgot Zip" Display="Dynamic"/>
</td>
</tr>
<tr>
<td Align="right"> </td>
<td Align="Left"><asp:button id="btsignup" text="Sign Up" onclink="submit" runat="server" />
</tr>
</table>
</form
</td>
<td>
</td>
</tr>
</table>
</td
</tr>
</tr>
<td
</td>
</tr
<tr>
<td>
<LoveShare:Footer runat="server" />
</td>
</tr>
</table>
</td>
</tr>
</table>
</body>
</html
Please help, I cannot figure out what is wrong(1) i havent gone through youe entire code but make sure you are passing in values in the same order as they appear in your query since OLEDB parameters are positional.
(2) in this sql stmt :
INSERT INTO tblUsers (FirstName, LastName, UserName, Password, Email, Address, City, State, Zip)
username, password, email etc are keywords. use [UserName], [Password], [Email]..etc
hth
No comments:
Post a Comment