Click here to Skip to main content
15,883,705 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more: , +
Hello Friends,


I wrote a code for updating the record ,after executing it is always return 0.

Please Help me.
My Code is..

C#
bool isresult = false;
            string connectionInfo = ConfigurationSettings.AppSettings["ConnectionString"];
            SqlConnection ObjSqlConnection = new SqlConnection(connectionInfo);
            ObjSqlConnection.Open();
            SqlTransaction ObjSqlTransaction = ObjSqlConnection.BeginTransaction();
            SqlCommand objSqlCommand = new SqlCommand("SP_UpDateDetails", ObjSqlConnection, ObjSqlTransaction);
            objSqlCommand.CommandType = CommandType.StoredProcedure;
            objSqlCommand.CommandTimeout = 500000;
            try
            {


                objSqlCommand.Parameters.Add("@regId", SqlDbType.VarChar).Value = (objCO_TR_Registration.RegistrationID);

                objSqlCommand.Parameters.Add("@SSLCNO", SqlDbType.VarChar).Value = (objCO_TR_Registration.SSLCNo);
               // objSqlCommand.Parameters.Add("@photo", DbType.Byte).Value = objCO_TR_Registration.Photo;

                //objSqlCommand.Parameters.Add("@VLFNO", SqlDbType.VarChar).Value = (objCO_TR_Registration.VLFNO);
                objSqlCommand.Parameters.Add("@Stud_name", SqlDbType.VarChar).Value = objCO_TR_Registration.Name;
                objSqlCommand.Parameters.Add("@FHG", SqlDbType.VarChar).Value = objCO_TR_Registration.FHG;
                objSqlCommand.Parameters.Add("@FHG_Name", SqlDbType.VarChar).Value = objCO_TR_Registration.FatherName;
                objSqlCommand.Parameters.Add("@Gender", SqlDbType.VarChar).Value = objCO_TR_Registration.gender;
                objSqlCommand.Parameters.Add("@MaritalStatus", DbType.String).Value = objCO_TR_Registration.MaritalStatus;

                objSqlCommand.Parameters.Add("@DOB", SqlDbType.VarChar).Value = objCO_TR_Registration.DateOfBirth;
                objSqlCommand.Parameters.Add("@Religion", SqlDbType.Char).Value = objCO_TR_Registration.ReligionId;
                objSqlCommand.Parameters.Add("@Income", SqlDbType.Decimal).Value = objCO_TR_Registration.AnnualIncome;

                objSqlCommand.Parameters.Add("@Address1", SqlDbType.VarChar).Value = objCO_TR_Registration.Address1;
                objSqlCommand.Parameters.Add("@Address2", SqlDbType.VarChar).Value = objCO_TR_Registration.Address2;
                objSqlCommand.Parameters.Add("@Pre_distCode", SqlDbType.Int).Value = objCO_TR_Registration.Pre_DistrictId;
                objSqlCommand.Parameters.Add("@Pre_talukcode", SqlDbType.Int).Value = objCO_TR_Registration.Pre_Taluq;
                objSqlCommand.Parameters.Add("@pinCode", SqlDbType.Int).Value = objCO_TR_Registration.PinCode;
                objSqlCommand.Parameters.Add("@PhoneNo", SqlDbType.NVarChar).Value = objCO_TR_Registration.PhoneNo;
                objSqlCommand.Parameters.Add("@MoblieNo", SqlDbType.VarChar).Value = objCO_TR_Registration.MobileNo;
                objSqlCommand.Parameters.Add("@EmailID", SqlDbType.VarChar).Value = objCO_TR_Registration.EmailId;
                objSqlCommand.Parameters.Add("@PAddress1", SqlDbType.VarChar).Value = objCO_TR_Registration.PAddress1;
                objSqlCommand.Parameters.Add("@PAddress2", SqlDbType.VarChar).Value = objCO_TR_Registration.PAddress2;

                objSqlCommand.Parameters.Add("@Per_distCode", SqlDbType.VarChar).Value = objCO_TR_Registration.Per_DistrictId;
                objSqlCommand.Parameters.Add("@Per_taluk", SqlDbType.VarChar).Value = objCO_TR_Registration.Per_Taluq;

                objSqlCommand.Parameters.Add("@ppinCode", SqlDbType.Int).Value = objCO_TR_Registration.PPinCode;
                objSqlCommand.Parameters.Add("@pPhoneNo", SqlDbType.NVarChar).Value = objCO_TR_Registration.PPhoneNo;
                objSqlCommand.Parameters.Add("@pMoblieNo", SqlDbType.Int).Value = "0";
                objSqlCommand.Parameters.Add("@College", SqlDbType.Int).Value = objCO_TR_Registration.CollegeId;
                objSqlCommand.Parameters.Add("@Course", SqlDbType.Int).Value = objCO_TR_Registration.CourseId;
                objSqlCommand.Parameters.Add("@Branch", SqlDbType.VarChar).Value = objCO_TR_Registration.branch;

                objSqlCommand.Parameters.Add("@Cduration", SqlDbType.Int).Value = objCO_TR_Registration.Cduration;
                objSqlCommand.Parameters.Add("@WhichYear", SqlDbType.Int).Value = objCO_TR_Registration.WhichYear;
                objSqlCommand.Parameters.Add("@Amount", SqlDbType.Decimal).Value = (objCO_TR_Registration.FeeAmount);
                objSqlCommand.Parameters.Add("@TotalAmount", SqlDbType.Decimal).Value = (objCO_TR_Registration.TotalAmount);
                objSqlCommand.Parameters.Add("@fOccupation", SqlDbType.VarChar).Value = objCO_TR_Registration.foccupation;
                objSqlCommand.Parameters.Add("@mOccupation", SqlDbType.VarChar).Value = objCO_TR_Registration.moccupation;
                objSqlCommand.Parameters.Add("@gOccupation", SqlDbType.VarChar).Value = objCO_TR_Registration.goccupation;
                objSqlCommand.Parameters.Add("@Otherloan", SqlDbType.VarChar).Value = objCO_TR_Registration.OtherLoan;
                objSqlCommand.Parameters.Add("@AcademicYear", SqlDbType.Int).Value = objCO_TR_Registration.AccademeicYear;

                int res = objSqlCommand.ExecuteNonQuery();
}
catch(Exception Ex)
Posted
Updated 16-Sep-11 20:02pm
v2
Comments
rkthiyagarajan 17-Sep-11 2:03am    
Use Pre tag..
jagadeesh123qqq 17-Sep-11 2:05am    
Thanks for your reply,

where i need to use pre tag..
P.Salini 17-Sep-11 2:09am    
Is your database getting updated
jagadeesh123qqq 17-Sep-11 2:10am    
ya.. i copied the script from sql pro-filer and executed but in C# it is showing 0.
jagadeesh123qqq 17-Sep-11 2:11am    
in sql it is returning 1 row affected

1 solution

You have to Commit your transaction.

ExecNonQuery returns the last insert count so make sure in your stored procedures you do not do anything else before exiting the procedure, to get the results.
 
Share this answer
 

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



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900