Friends -
Here is a simple .aspx file I got somewhere on the net.
__________________________________________________________
<%@ Page Language="C#" AutoEventWireup="true" CodeFile="CS.aspx.cs" Inherits="CS" %>
<title>
body
{
font-family: Arial;
font-size: 10pt;
}
input
{
width: 200px;
}
table
{
border: 1px solid #ccc;
}
table th
{
background-color: #F7F7F7;
color: #333;
font-weight: bold;
}
table th, table td
{
padding: 5px;
border-color: #ccc;
}
Registration
|
Username
| <asp:textbox id="txtUsername" runat="server">
| <asp:requiredfieldvalidator errormessage="Required" forecolor="Red" controltovalidate="txtUsername"
="" runat="server">
|
Password
| <asp:textbox id="txtPassword" runat="server" textmode="Password">
| <asp:requiredfieldvalidator errormessage="Required" forecolor="Red" controltovalidate="txtPassword"
="" runat="server">
|
Confirm Password
| <asp:textbox id="txtConfirmPassword" runat="server" textmode="Password">
| <asp:comparevalidator errormessage="Passwords do not match." forecolor="Red" controltocompare="txtPassword"
="" controltovalidate="txtConfirmPassword" runat="server">
|
Email
| <asp:textbox id="txtEmail" runat="server">
| <asp:requiredfieldvalidator errormessage="Required" display="Dynamic" forecolor="Red"
="" controltovalidate="txtEmail" runat="server">
<asp:regularexpressionvalidator runat="server" display="Dynamic" validationexpression="\w+([-+.']\w+)*@\w+([-.]\w+)*\.\w+([-.]\w+)*"
="" controltovalidate="txtEmail" forecolor="Red" errormessage="Invalid email address.">
|
| <asp:button text="Submit" runat="server" onclick="RegisterUser">
| |
__________________________________________
Here is the Code behind C# Code.
__________________________________
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Data;
using System.Configuration;
using System.Data.SqlClient;
using System.Web.Configuration;
public partial class CS : System.Web.UI.Page
{
protected void RegisterUser(object sender, EventArgs e)
{
int userId = 0;
string constr = ConfigurationManager.ConnectionStrings["constr"].ConnectionString;
using (SqlConnection con = new SqlConnection(constr))
{
using (SqlCommand cmd = new SqlCommand("Insert_User"))
{
using (SqlDataAdapter sda = new SqlDataAdapter())
{
cmd.CommandType = CommandType.StoredProcedure;
cmd.Parameters.AddWithValue("@Username", txtUsername.Text.Trim());
cmd.Parameters.AddWithValue("@Password", txtPassword.Text.Trim());
cmd.Parameters.AddWithValue("@Email", txtEmail.Text.Trim());
cmd.Connection = con;
con.Open();
userId = Convert.ToInt32(cmd.ExecuteScalar());
con.Close();
}
}
string message = string.Empty;
switch (userId)
{
case -1:
message = "Username already exists.\\nPlease choose a different username.";
break;
case -2:
message = "Supplied email address has already been used.";
break;
default:
message = "Registration successful.\\nUser Id: " + userId.ToString();
break;
}
ClientScript.RegisterStartupScript(GetType(), "alert", "alert('" + message + "');", true);
}
}
}
___________________________________________
Here is the Stored Procedure
____________________________
--Insert_User 'Mudassar2', '12345', 'mudassar@aspsnippets.com'
ALTER PROCEDURE [dbo].[Insert_User]
@Username NVARCHAR(20),
@Password NVARCHAR(20),
@Email NVARCHAR(30)
AS
BEGIN
SET NOCOUNT ON;
IF EXISTS(SELECT UserId FROM Users WHERE Username = @Username)
BEGIN
SELECT -1 -- Username exists.
END
ELSE IF EXISTS(SELECT UserId FROM Users WHERE Email = @Email)
BEGIN
SELECT -2 -- Email exists.
END
ELSE
BEGIN
INSERT INTO [Users]
([Username]
,[Password]
,[Email]
,[CreatedDate])
VALUES
(@Username
,@Password
,@Email
,GETDATE())
SELECT SCOPE_IDENTITY() -- UserId
END
END
____________________________________
What I have tried:
I tried in Local server which works well - but not in Godaddy webhost which gives error:
I tested with other simple database connection which works well. I am unable to fix this Parameter incorrect error.
The parameter is incorrect
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.ComponentModel.Win32Exception: The parameter is incorrect
How to solve this - Please help.