Solved

database insert using MS Application block ExecuteNonQuery method

Posted on 2004-08-16
2
403 Views
Last Modified: 2010-04-15
Hi all, I'm new to c# and am trying to do a basic insert into a sql database. I keep getting the following error -

System.Data.SqlClient.SqlException: Error converting data type char to int. at System.Data.SqlClient.SqlCommand.ExecuteReader(CommandBehavior cmdBehavior, RunBehavior runBehavior, Boolean returnStream) at System.Data.SqlClient.SqlCommand.ExecuteNonQuery() at Microsoft.ApplicationBlocks.Data.SqlHelper.ExecuteNonQuery(SqlConnection connection, CommandType commandType, String commandText, SqlParameter[] commandParameters) in C:\Program Files\Microsoft Application Blocks for .NET\Data Access v2\Code\CS\Microsoft.ApplicationBlocks.Data\SQLHelper.cs:line 335 at CZRDP.RDCPages.NewRecord.butSubmitDetails_Click(Object sender, EventArgs e) in e:\rmds\czrdp\rdcpages\newrecord.aspx.cs:line 385

This is the code that I'm using any help would be much appreciated

SqlParameter paramSubscriber = new SqlParameter("@SubscriberNo", SqlDbType.Char, 20,"SubscriberNo");
                    paramSubscriber.Value = txtSubscriberNumber.Text;
                    SqlParameter paramAccType = new SqlParameter("@AccountTypeID", SqlDbType.Int, 4,"AccountTypeID");
                    paramAccType.Value = drpAccType.SelectedValue;                                  
                    SqlParameter paramComp = new SqlParameter("@Competitor",SqlDbType.Bit,1,"Competitor");
                    paramComp.Value = chkCompetitor.Checked;                        
                    SqlParameter paramCompName = new SqlParameter("@CompanyName",SqlDbType.Char,80,"CompanyName");
                    paramCompName.Value = txtCompanyName.Text;
                    SqlParameter paramSalutation = new SqlParameter("@SalutationID",SqlDbType.Int,4,"SalutationID");
                    paramSalutation.Value = drpSupportSalutation.SelectedValue;
                    SqlParameter paramFirstName = new SqlParameter("@FirstName",SqlDbType.Char,80,"FirstName");
                    paramFirstName.Value = txtFirstName.Text;
                    SqlParameter paramLastName = new SqlParameter("@LastName",SqlDbType.Char,80,"LastName");
                    paramLastName.Value = txtLastName.Text;
                    SqlParameter paramSupportLevel = new SqlParameter("@SupportLevelID",SqlDbType.Int,4,"SupportLevelID");
                    paramSupportLevel.Value = drpSupportLevel.SelectedValue;
                    SqlParameter paramProduct = new SqlParameter("@ProductID",SqlDbType.Int,4,"ProductID");
                    paramProduct.Value = drpSupportedProducts.SelectedValue;
                    SqlParameter paramAddr1 = new SqlParameter("@Address1",SqlDbType.Char,80,"Address1");
                    paramAddr1.Value = txtaddress1.Text;
                    SqlParameter paramAddr2 = new SqlParameter("@Address2",SqlDbType.Char,80,"Address2");
                    paramAddr2.Value = txtaddress2.Text;
                    SqlParameter paramCity = new SqlParameter("@City",SqlDbType.Char,80,"City");
                    paramCity.Value = txtcity.Text;
                    SqlParameter paramCounty = new SqlParameter("@County",SqlDbType.Char,80,"County");
                    paramCounty.Value = txtcounty.Text;
                    SqlParameter paramPostcode = new SqlParameter("@Postcode",SqlDbType.Char,10,"Postcode");
                    paramPostcode.Value = txtPostcode.Text;
                    SqlParameter paramCountry = new SqlParameter("@Country",SqlDbType.Char,80,"Country");
                    paramCountry.Value = txtCountry.Text;
                    SqlParameter paramPhone = new SqlParameter("@PhoneNo",SqlDbType.Char,40,"PhoneNo");
                    paramPhone.Value = txtPhoneNumber.Text;
                    SqlParameter paramCCSSalutation = new SqlParameter("@CCSSalutationID",SqlDbType.Int,4,"CCSSalutationID");
                    paramCCSSalutation.Value = drpSupportSalutation.SelectedValue;
                    SqlParameter paramCCSSFirstName = new SqlParameter("@CCSFirstName",SqlDbType.Char,80,"CCSFirstName");
                    paramCCSSFirstName.Value = txtSupportFirstName.Text;
                    SqlParameter paramCCSSLastName = new SqlParameter("@CCSLastName",SqlDbType.Char,80,"CCSLastName");
                    paramCCSSLastName.Value = txtSupportLastName.Text;
                    SqlParameter paramCCSRole = new SqlParameter("@CCSRole",SqlDbType.Char,80,"CCSRole");
                    paramCCSRole.Value = txtClientRole.Text;
                    SqlParameter paramMembershipStartDate = new SqlParameter("@MembershipStartDate",SqlDbType.DateTime,8,"MembershipStartDate");
                    paramMembershipStartDate.Value = txtMembershipDate.Text;
                    SqlParameter paramAgreeDate = new SqlParameter("@RDCAgreementDate",SqlDbType.DateTime,8,"RDCAgreementDate");
                    paramAgreeDate.Value = txtSignedAgreeDate.Text;
                    SqlParameter paramContractType = new SqlParameter("@ContractTypeID",SqlDbType.Int,4,"ContractTypeID");
                    paramContractType.Value = drpContractType.SelectedValue;
                    SqlParameter paramContractTypeDate = new SqlParameter("@ContractTypeSignedDate",SqlDbType.DateTime,8,"ContractTypeSignedDate");
                    paramContractTypeDate.Value = txtSignedConType.Text;
                    SqlParameter paramAccManager = new SqlParameter("@AccountManager",SqlDbType.Char,80,"AccountManager");
                    paramAccManager.Value = txtAccManager.Text;
                    SqlParameter paramBusAdmin = new SqlParameter("@BusinessAdmin",SqlDbType.Char,80,"BusinessAdmin");
                    paramBusAdmin.Value = txtBusinessAdmin.Text;
                    SqlParameter paramNamedEmail = new SqlParameter("@NamedUserEmailAddress",SqlDbType.Char,80,"NamedUserEmailAddress");
                    paramNamedEmail.Value = txtSupportEmailAddress.Text;
                    SqlParameter paramSupportEmail = new SqlParameter("@CCSEmailAddress",SqlDbType.Char,80,"CCSEmailAddress");
                    paramSupportEmail.Value = txtEmailAddress.Text;
                    SqlParameter paramOldRevenue = new SqlParameter("@OldRevenue",SqlDbType.Int,4,"OldRevenue");
                    paramOldRevenue.Value = txtOldOldRevenue.Text;
                    SqlParameter paramOldNewRevenue = new SqlParameter("@OldNewRevenue",SqlDbType.Int,4,"OldNewRevenue");
                    paramOldNewRevenue.Value = txtOldNewRevenue.Text;
                    SqlParameter paramNewNewRevenue = new SqlParameter("@NewNewRevenue",SqlDbType.Int,4,"NewNewRevenue");
                    paramNewNewRevenue.Value = txtNewNewRevenue.Text;
                    SqlParameter paramCreditsBought = new SqlParameter("@TotalCreditsBought",SqlDbType.Int,4,"TotalCreditsBought");
                    paramCreditsBought.Value = txtCreditsBought.Text;
                    SqlParameter paramCreditsUsed = new SqlParameter("@TotalCreditsUsed",SqlDbType.Int,4,"TotalCreditsUsed");
                    paramCreditsUsed.Value = txtCreditsUsed.Text;
                    SqlParameter paramDateOpened = new SqlParameter("@DateOpened",SqlDbType.DateTime,8,"DateOpened");
                    paramDateOpened.Value = txtDateOpened.Text;
                    SqlParameter paramDateClosed = new SqlParameter("@DateClosed",SqlDbType.DateTime,8,"DateClosed");
                    paramDateClosed.Value = txtDateClosed.Text;
                    SqlParameter paramSiebelSRNo = new SqlParameter("@SiebelSRNo",SqlDbType.Char,80,"SiebelSRNo");
                    paramSiebelSRNo.Value = txtSiebelNumber.Text;
                    SqlParameter paramBillable = new SqlParameter("@Billable",SqlDbType.Bit,1,"Billable");
                    paramBillable.Value = chkBillable.Checked;
                    SqlParameter paramRegion = new SqlParameter("@RegionID",SqlDbType.Int,4,"RegionID");
                    paramRegion.Value = drpRegionID.SelectedValue;
                    SqlParameter paramClientStatus = new SqlParameter("@ClientStatusID",SqlDbType.Int,4,"ClientStatusID");
                    paramClientStatus.Value = drpSupportClientStatus.SelectedValue;
                   
               try
               {
                    int result;
                    result = SqlHelper.ExecuteNonQuery(SqlUtility.Connection,CommandType.StoredProcedure,"itblSubscriber",paramSubscriber,paramAccType,
                         paramComp,paramCompName,
                         paramSalutation,paramFirstName,
                         paramLastName,paramSupportLevel,
                         paramProduct,paramAddr1,
                         paramAddr2,paramCity,
                         paramCounty,paramPostcode,
                         paramCountry,paramPhone,
                         paramCCSSalutation,paramCCSSFirstName,
                         paramCCSSLastName,paramCCSRole,
                         paramMembershipStartDate,
                         paramAgreeDate,
                         paramContractType,
                         paramContractTypeDate,
                         paramAccManager,paramBusAdmin,
                         paramNamedEmail,paramSupportEmail,
                         paramOldRevenue,paramOldNewRevenue,
                         paramNewNewRevenue,paramCreditsBought,
                         paramCreditsUsed,paramDateOpened,
                         paramDateClosed,paramSiebelSRNo,
                         paramBillable,paramRegion,
                         paramClientStatus);    
               }          
               catch (Exception ex)
               {
                    Response.Write(ex.ToString());
               }
               Response.Redirect("SearchRecord.aspx",true);
          }
0
Comment
Question by:Browski
2 Comments
 

Accepted Solution

by:
hatukaze earned 125 total points
ID: 11809182
One of your parameters is of type string (*char on sql server), but the stored procedure expects it to be of type int.

Open your stored procedure and check if theres a mismatch of datatypes.
0
 

Author Comment

by:Browski
ID: 11809745
Many thanks hatukaze
0

Featured Post

Announcing the Most Valuable Experts of 2016

MVEs are more concerned with the satisfaction of those they help than with the considerable points they can earn. They are the types of people you feel privileged to call colleagues. Join us in honoring this amazing group of Experts.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Extention Methods in C# 3.0 by Ivo Stoykov C# 3.0 offers extension methods. They allow extending existing classes without changing the class's source code or relying on inheritance. These are static methods invoked as instance method. This…
Exception Handling is in the core of any application that is able to dignify its name. In this article, I'll guide you through the process of writing a DRY (Don't Repeat Yourself) Exception Handling mechanism, using Aspect Oriented Programming.
This Micro Tutorial will teach you how to censor certain areas of your screen. The example in this video will show a little boy's face being blurred. This will be demonstrated using Adobe Premiere Pro CS6.
This video shows how to quickly and easily add an email signature for all users on Exchange 2016. The resulting signature is applied on a server level by Exchange Online. The email signature template has been downloaded from: www.mail-signatures…

813 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

18 Experts available now in Live!

Get 1:1 Help Now