Solved

database insert using MS Application block ExecuteNonQuery method

Posted on 2004-08-16
2
400 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

What Is Threat Intelligence?

Threat intelligence is often discussed, but rarely understood. Starting with a precise definition, along with clear business goals, is essential.

Join & Write a Comment

Introduction                                                 Was the var keyword really only brought out to shorten your syntax? Or have the VB language guys got their way in C#? What type of variable is it? All will be revealed.   Also called…
This article introduced a TextBox that supports transparent background.   Introduction TextBox is the most widely used control component in GUI design. Most GUI controls do not support transparent background and more or less do not have the…
Sending a Secure fax is easy with eFax Corporate (http://www.enterprise.efax.com). First, Just open a new email message.  In the To field, type your recipient's fax number @efaxsend.com. You can even send a secure international fax — just include t…
This demo shows you how to set up the containerized NetScaler CPX with NetScaler Management and Analytics System in a non-routable Mesos/Marathon environment for use with Micro-Services applications.

707 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

13 Experts available now in Live!

Get 1:1 Help Now