Bineesh  Viswanath

Bineesh Viswanath

  • NA
  • 1k
  • 780.8k

Insert Function in ASP.NET

Aug 31 2013 2:06 AM
Sir, I am getting an error in the Save function in asp.net:-

The code is being shown below. I put BreakPoint in customer Sp class and btnSave_click event.

None of the control holds NULL value during this function.


This is my form Page:-


There are two error getting.

1)




2)


here the Codes:-



1) SQL SP:-

ALTER PROCEDURE  CustomerAdd
@customerCode numeric(18,0),
 @firstName varchar(20),
  @lastName varchar(20),
  @Gender varchar(20),
  @Address varchar(20),
  @City varchar(20),
  @State varchar(20),
  @County varchar(20),
   @pinCode varchar(20),
    @mobileNo varchar(20) ,
    @Email varchar(20),
    @joinDate datetime,
    @userName varchar(20),
     @Password varchar(20)

AS
   
   
INSERT INTO tbl_Customer
  (customerCode, firstName, lastName, Gender, Address, City, State, County, pinCode, mobileNo, Email, joinDate, userName, Password)
VALUES  (@customerCode, @firstName, @lastName, @Gender, @Address, @City, @State, @County, @pinCode, @mobileNo, @Email, @joinDate, @userName, @Password)


2) Customer Info class:-


pPublic class CInfo
  {
  public decimal customerId
  {
  get;
  set;
  }
  public string customerCode
  {
  get;
  set;
  }
  public string firstName
  {
  get;
  set;
  }
  public string lastName
  {
  get;
  set;
  }
  public string Gender
  {
  get;
  set;
  }
  public string Address
  {
  get;
  set;
  }
  public string City
  {
  get;
  set;
  }
  public string State
  {
  get;
  set;
  }
  public string County
  {
  get;
  set;
  }
  public string pinCode
  {
  get;
  set;
  }
  public string mobileNo
  {
  get;
  set;
  }
  public string Email
  {
  get;
  set;
  }
  public DateTime joinDate
  {
  get;
  set;
  }
  public string userName
  {
  get;
  set;
  }
  public string Password
  {
  get;
  set;
  }
}


3) Customer SP class:-

public void CustomerAdd (CInfo InfoCustomer)
  {
  try
  {
  if (sqlCon.State == ConnectionState.Closed)
  {
  sqlCon.Open();
  }
  SqlCommand c = new SqlCommand("CustomerAdd", sqlCon);
  c.CommandType = CommandType.StoredProcedure;
  c.Parameters.Add("customerCode", SqlDbType.Decimal).Value = InfoCustomer.customerCode;
  c.Parameters.Add("firstName", SqlDbType.VarChar).Value = InfoCustomer.firstName;
  c.Parameters.Add("lastName", SqlDbType.VarChar).Value = InfoCustomer.lastName;
  c.Parameters.Add("Gender", SqlDbType.VarChar).Value = InfoCustomer.Gender;
  c.Parameters.Add("Address", SqlDbType.VarChar).Value = InfoCustomer.Address;
  c.Parameters.Add("City", SqlDbType.VarChar).Value = InfoCustomer.City;
  c.Parameters.Add("State", SqlDbType.VarChar).Value = InfoCustomer.State;
  c.Parameters.Add("Country", SqlDbType.VarChar).Value = InfoCustomer.County;
  c.Parameters.Add("pinCode", SqlDbType.VarChar).Value = InfoCustomer.pinCode;
  c.Parameters.Add("mobileNo", SqlDbType.VarChar).Value = InfoCustomer.mobileNo;
  c.Parameters.Add("Email", SqlDbType.VarChar).Value = InfoCustomer.Email;
  c.Parameters.Add("joinDate", SqlDbType.DateTime).Value = InfoCustomer.joinDate;
  c.Parameters.Add("userName", SqlDbType.VarChar).Value = InfoCustomer.userName;
  c.Parameters.Add("Password", SqlDbType.VarChar).Value = InfoCustomer.Password;
  int inCount = c.ExecuteNonQuery();
  if (inCount > 0)
  {
  MessageBox.Show("Saved Successfully");
  }
  }
  catch (Exception)
  {
  throw;
  }
  finally
  {
  sqlCon.Close();
  }
  }


4) And Finally, btnSave_Click Event:-


protected void btnSave_Click ( object sender , EventArgs e )
  {
  CSP sp = new CSP ( );
  CInfo Info = new CInfo ( );
  Info . customerCode = txtCustomerCode . Text;
  Info . firstName = txtFirstName . Text;
  Info . lastName = txtLastName . Text;
  Info . Gender = ddlGender . SelectedValue . ToString ( );
  Info . Address = txtAddress . Text;
  Info . City = txtCity . Text;
  Info . State = txtState . Text;
  Info . County = txtCountry . Text;
  Info . pinCode = txtPinCode . Text;
  Info . mobileNo = txtMobile . Text;
  Info . Email = txtEmail . Text;
  Info . joinDate = DateTime . Parse ( txtJoinDate . Text );
  Info . Password = txtPassword1 . Text;
  Info . userName = txtUserName1 . Text;
  sp . CustomerAdd ( Info );
  mvCustomer . ActiveViewIndex = 0;
  GridFill ( );
 
  }





Answers (4)