Click here to Skip to main content
Rate this: bad
good
Please Sign up or sign in to vote.
See more: C# ASP.NET
con = new SqlConnection(ConfigurationManager.ConnectionStrings["amms"].ConnectionString);
                cmd = new SqlCommand();
                con.Open();
                cmd.Connection = con;
 
                cmd.CommandType = CommandType.StoredProcedure;
                cmd.CommandText = "AddTempMember";
                cmd.Parameters.AddWithValue("@ParentId", txtPlaceUnderID.Text.Trim());
                cmd.Parameters.AddWithValue("@ThroughOverId", (txtSponsorID.Text.Trim() == "" ? null : txtSponsorID.Text.Trim()));
                cmd.Parameters.AddWithValue("@Leg", rdolstNode.SelectedItem.Value.Trim());
                cmd.Parameters.AddWithValue("@Title", ddlTitle.SelectedItem.Text.Trim());
                cmd.Parameters.AddWithValue("@FirstName", txtFirstName.Text.Trim());
                cmd.Parameters.AddWithValue("@LastName", txtLastName.Text.Trim());
                cmd.Parameters.AddWithValue("@Type", ddlFathersHusband.SelectedItem.Value.Trim());
                cmd.Parameters.AddWithValue("@FathersName", txtFathersName.Text.Trim());
                cmd.Parameters.AddWithValue("@MothersName", null);
                cmd.Parameters.AddWithValue("@MaritalStatus", ddlMaritalStatus.SelectedItem.Text.Trim());
                cmd.Parameters.AddWithValue("@Address", txtAddress.Text.Trim());
                cmd.Parameters.AddWithValue("@City", txtCity.Text.Trim());
                cmd.Parameters.AddWithValue("@State", ddlState.SelectedItem.Text.Trim());
                cmd.Parameters.AddWithValue("@Country", txtCountry.Text.Trim());
                cmd.Parameters.AddWithValue("@Pin", txtPinCode.Text.Trim());
                cmd.Parameters.AddWithValue("@Std", txtStdCode.Text.Trim());
                cmd.Parameters.AddWithValue("@Phone", txtPhone.Text.Trim());
                cmd.Parameters.AddWithValue("@Mobile", txtMobile.Text.Trim());
                cmd.Parameters.AddWithValue("@Email", txtEmail.Text.Trim());
                cmd.Parameters.AddWithValue("@LoginId", null);
                cmd.Parameters.AddWithValue("@Password", null);
                cmd.Parameters.AddWithValue("@DOB", (txtDOB.Text.Trim() == "" ? null : Convert.ToDateTime(txtDOB.Text.Trim()).ToString("MM/dd/yyyy")));
                cmd.Parameters.AddWithValue("@Age", lblAge.Text.Trim());
                cmd.Parameters.AddWithValue("@Sex", ddlGender.SelectedItem.Value.Trim());
                cmd.Parameters.AddWithValue("@PAN", txtPanCardNo.Text.Trim());
                cmd.Parameters.AddWithValue("@PinNo", null);
                cmd.Parameters.AddWithValue("@NomineeName", txtNomineeName.Text.Trim());
                cmd.Parameters.AddWithValue("@NomineeRelation", txtNomineeRelation.Text.Trim());
                cmd.Parameters.AddWithValue("@NomineeDOB", (txtNomineeDOB.Text.Trim() == "" ? null : Convert.ToDateTime(txtNomineeDOB.Text.Trim()).ToString("MM/dd/yyyy")));
                cmd.Parameters.AddWithValue("@ProductCode", ddlProduct.SelectedItem.Value.Trim());
                cmd.Parameters.AddWithValue("@PaymentOption", null);
                cmd.Parameters.AddWithValue("@PaymentMode", ddlPaymentMode.SelectedItem.Value.Trim());
                cmd.Parameters.AddWithValue("@Amount", txtAmount.Text.Trim());
                cmd.Parameters.AddWithValue("@AmountBalance", txtBalanceAmount.Text.Trim());
                cmd.Parameters.AddWithValue("@BankName", txtBankName.Text.Trim());
                cmd.Parameters.AddWithValue("@DDChequeNo", txtChequeDDNo.Text.Trim());
                cmd.Parameters.AddWithValue("@DDChequeDate", (txtChequeDDDate.Text.Trim() == "" ? null : Convert.ToDateTime(txtChequeDDDate.Text.Trim()).ToString("MM/dd/yyyy")));
                cmd.Parameters.AddWithValue("@Payable", txtPayble.Text.Trim());
                cmd.Parameters.AddWithValue("@MemberAccNo", txtCBSacNo.Text.Trim());
                cmd.Parameters.AddWithValue("@MemberBankName", txtMemberBankName.Text.Trim());
                cmd.Parameters.AddWithValue("@MemberBranch", txtBankBranch.Text.Trim());
                cmd.Parameters.AddWithValue("@DepotCode", (txtBranchCode.Text.Trim() == "" ? null : txtBranchCode.Text.Trim()));
                cmd.Parameters.AddWithValue("@ReceiptNo", null);
                cmd.Parameters.AddWithValue("@JoiningDate", (txtJoiningDate.Text.Trim() == "" ? null : Convert.ToDateTime(txtJoiningDate.Text.Trim()).ToString("MM/dd/yyyy")));
               cmd.Parameters.AddWithValue("@CreatedBy", Convert.ToString(Session["UserId"]));
                cmd.Parameters.AddWithValue("@MemId", 0).Direction = ParameterDirection.InputOutput;
                cmd.Parameters.AddWithValue("@msg", 0).Direction = ParameterDirection.InputOutput;
                cmd.ExecuteNonQuery();
                con.Close();
 

And the Procedure is:
 
ALTER PROCEDURE [dbo].[AddTempMember](@ParentId int,@ThroughOverId int, @Leg VARCHAR(50),@Title varchar(50),@FirstName varchar(50),@LastName varchar(50), @Type varchar(50),@FathersName varchar(50),@MothersName varchar(50), @MaritalStatus varchar(50), @Address varchar(50), @City varchar(50), @State varchar(50),@Country varchar(50),@Pin varchar(50),@Std varchar(50),@Phone varchar(50),@Mobile varchar(50),@Email varchar(50),@LoginId varchar(50),@Password varchar(50),@DOB date,@Age VARCHAR(50),@Sex varchar(50),@PAN varchar(50),@NomineeName varchar(50),@NomineeRelation varchar(50),@NomineeDOB varchar(50),@ProductCode varchar(50),@PaymentOption varchar(50),@PaymentMode varchar(50),@Amount money,@AmountBalance money,@BankName varchar(50),@DDChequeNo varchar(50),@DDChequeDate date,@Payable varchar(50),@MemberAccNo varchar(50),@MemberBankName varchar(50),@MemberBranch varchar(50),@DepotCode varchar(50),@ReceiptNo varchar(50),@JoiningDate varchar(50),@CreatedBy varchar(50),@MemId int,@msg varchar(50))
 
AS BEGIN
INSERT INTO Members(ParentId, ThroughOverId,Leg,Title,FirstName,LastName,Type,FathersName,MothersName,MaritalStatus,Address ,City,State,Country,Pin,Std,Phone,Mobile,Email,LoginId,Password,DOB,Age,Sex,PAN,NomineeName,NomineeRelation,NomineeDOB,ProductCode,PaymentOption,PaymentMode,Amount,AmountBalance,BankName,DDChequeNo,DDChequeDate,Payable,MemberAccNo,MemberBankName,MemberBranch,DepotCode,ReceiptNo,JoiningDate,CreatedBy,MemId,msg)
values (@ParentId,@ThroughOverId,@Leg,@Title,@FirstName,@LastName,@Type,@FathersName,@MothersName,@MaritalStatus,@Address ,@City,@State ,@Country,@Pin,@Std,@Phone,@Mobile,@Email,@LoginId,@Password,@DOB,@Age,@Sex,@PAN,@NomineeName,@NomineeRelation,@NomineeDOB,@ProductCode,@PaymentOption,@PaymentMode,@Amount,@AmountBalance,@BankName,@DDChequeNo,@DDChequeDate,@Payable,@MemberAccNo,@MemberBankName,@MemberBranch,@DepotCode,@ReceiptNo,@JoiningDate,@CreatedBy,@MemId,@msg)
END
Posted 4-Oct-12 0:12am
Comments
Dylan Morley at 4-Oct-12 6:13am
   
What's the problem? Some sort of Exception message? If so, what is it?!
Mohd. Mukhtar at 4-Oct-12 6:14am
   
What error you getting??
kushmanish at 4-Oct-12 6:23am
   
Procedure or function AddTempMember has too many arguments specified.
Rickin Kane at 4-Oct-12 6:14am
   
but where are you getting error and what is the error , have you debug the code to check where exactly its failed , have you run the profiler in SQL to check if the SP is giving the error , we possible cannot know what error it is even wothout knowing the error
n.podbielski at 4-Oct-12 6:20am
   
If you asking if code is good or bad it's definitively badly written.
kushmanish at 4-Oct-12 6:22am
   
what is the right method?
n.podbielski at 4-Oct-12 7:25am
   
For starter don't place data access code in code behind of Page or User Control.
Place it in separate file.
Don't use sql procedures. It's pain in the back to maintain it.
Oshtri Deka at 4-Oct-12 6:20am
   
To many parameters?!
Does the procedure fill only one or several tables? I'm just being curious.
aspnet_regiis at 4-Oct-12 7:22am
   
I think the problem is not with the code but with the person who posted it...without any explanation of the error...::laugh::
Rate this: bad
good
Please Sign up or sign in to vote.

Solution 2

Put some debug point's and debug the code step by step and identify the line of error and please provide the error message with more description.
  Permalink  
Rate this: bad
good
Please Sign up or sign in to vote.

Solution 1

Friend, please verify the data type of parameters passed by you as I saw there is some un-matching between procedure required parameter data type and passed parameter data type (eg: @ThroughOverID, @NomineeDOB, @JoiningDate). please let me know if you required more on it.
 
Thanks,
Ambesha
  Permalink  

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



Advertise | Privacy | Mobile
Web02 | 2.8.141015.1 | Last Updated 4 Oct 2012
Copyright © CodeProject, 1999-2014
All Rights Reserved. Terms of Service
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100