I am trying to make zip-code a VarChar in the SQL Database type and have it submit in the database with letters and numbers. When the zip-code has the int SQL Database type the form is submitted into the zip column in the database, but when the value of the zip-code is VarChar 50 the value is not submitted to the new column in the database named zipPostal.
Here is the code in aspx:
<asp:Label runat="server" ID="zipLabel" AssociatedControlID="zip">Zip/Postal
Code</asp:Label>
<asp:TextBox ID="zip" name="zip" runat="server"></asp:TextBox>
Here is the snippets of the code in C#:
/// Form post data from registration form
string username = Request.Form["UserName"];
string first = Request.Form["first"];
string last = Request.Form["last"];
string zip = Request.Form["zip"];
sqlCommand.Parameters.Add(new SqlParameter("@email", SqlDbType.VarChar, 50,
ParameterDirection.Input, false, 0, 0, "", DataRowVersion.Proposed, emails));
sqlCommand.Parameters.Add(new SqlParameter("@username", SqlDbType.VarChar, 15,
ParameterDirection.Input, false, 0, 0, "", DataRowVersion.Proposed, username));
sqlCommand.Parameters.Add(new SqlParameter("@firstName", SqlDbType.VarChar, 20,
ParameterDirection.Input, false, 0, 0, "", DataRowVersion.Proposed, first));
sqlCommand.Parameters.Add(new SqlParameter("@lastName", SqlDbType.VarChar, 20,
ParameterDirection.Input, false, 0, 0, "", DataRowVersion.Proposed, last));
sqlCommand.Parameters.Add(new SqlParameter("@zip", SqlDbType.VarChar, 50,
ParameterDirection.Input, false, 0, 0, "", DataRowVersion.Proposed, zip));
SQL Command type:
int chk = sqlCommand.ExecuteNonQuery();
public string CheckEmail(string Email)
{
string returnValue = string.Empty;
SqlConnection conn = new SqlConnection(strConnection);
SqlCommand sqlCommand = new SqlCommand
("CheckEmailAvailability", conn);
try
{
sqlCommand.CommandType =
CommandType.StoredProcedure;
sqlCommand.Parameters.AddWithValue("@Email",
Email.Trim());
conn.Open();
returnValue = sqlCommand.ExecuteScalar().ToString();
conn.Close();
}
catch
{
}
finally
{
conn.Close();
sqlCommand.Dispose();
}
return returnValue;
}
////
public string CheckUsername(string Username)
{
string returnValue = string.Empty;
SqlConnection conn = new SqlConnection(strConnection);
SqlCommand sqlCommand = new SqlCommand
("CheckUsernameAvailability", conn);
try
{
sqlCommand.CommandType =
CommandType.StoredProcedure;
sqlCommand.Parameters.AddWithValue("@UserName",
Username.Trim());
conn.Open();
returnValue = sqlCommand.ExecuteScalar().ToString();
conn.Close();
}
catch
{
}
finally
{
conn.Close();
sqlCommand.Dispose();
}
return returnValue;
}
}
//STORED PROCEDURE
if (username != "")
{
string checkUN = CheckUsername(username);
if (checkUN == "true")
{
Label2.Text = "Username already exists.";
gotoauth = 0;
return;
}
}
//[ckc] end check username
if (password != confirmpwd)
{
Label2.Text = "The Password and Confirmation
Password must match.";
gotoauth = 0;
return;
}
//connection with db and call procedure.
SqlConnection conn = new SqlConnection(strConnection);
SqlCommand sqlCommand = new SqlCommand
("customers_insert", conn);
sqlCommand.CommandType = CommandType.StoredProcedure;
conn.Open();
try
{
if (gotoauth == 0)
{}
else
{
var customerGateway = new
CustomerGateway(_loginApikey, _TransactionKey,
ServiceMode.Live);
var NewCustomer = customerGateway.CreateCustomer
(emails, "Live User Account");
var datetime = DateTime.Now.ToString();
string proid = NewCustomer.ProfileID;
Session["Customerproid"] = proid;
/// SQL Procedure
SET QUOTED_IDENTIFIER ON
GO
ALTER PROCEDURE [dbo].[customers_insert]
@email varchar(50) ,
@username varchar(15) ,
@firstName varchar(20) ,
@lastName varchar(20) ,
@country varchar(50) ,
@address varchar(100) ,
@city varchar(100) ,
@state varchar(50) ,
@account bigint = null ,
@profileID bigint = null ,
@password varchar(20) ,
@customerNumber int = null ,
@question varchar(50) ,
@answer varchar(50) ,
@dob varchar(50) ,
@AccountNumber varchar(50) = null ,
@PinNumber varchar(50) = null ,
@PhoneNumber varchar(50) = null,
@ApprovalID int,
@DateTime varchar (50) = null,
@thoughts varchar (100) = null,
@zip varchar (50) = null
AS
INSERT [dbo].[customers]
(
[email],
[username],
[firstName],
[lastName],
[country],
[address],
[city],
[state],
[account],
[profileID],
[password],
[customerNumber],
[question],
[answer],
[dob],
[AccountNumber],
[PinNumber],
[PhoneNumber],
[ApprovalID],
[DateTime],
[thoughts],
[zip]
)
VALUES
(
@email,
@username,
@firstName,
@lastName,
@country,
@address,
@city,
@state,
@account,
@profileID,
@password,
@customerNumber,
@question,
@answer,
@dob,
@AccountNumber,
@PinNumber,
@PhoneNumber,
@ApprovalID,
@DateTime,
@thoughts,
@zip
)
In the SQL Database, there is a column for zip (int, not null) and a column for zipPostal (varChar(50), null). I want the zip-code data to be going in the zipPostal column so it accepts letters and numbers.
Any help would be greatly appreciated.