Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

database insert using MS Application block ExecuteNonQuery method

Posted on 2004-08-16
2
Medium Priority
?
415 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
2 Comments
 

Accepted Solution

by:
hatukaze earned 500 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

Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

We all know that functional code is the leg that any good program stands on when it comes right down to it, however, if your program lacks a good user interface your product may not have the appeal needed to keep your customers happy. This issue can…
Calculating holidays and working days is a function that is often needed yet it is not one found within the Framework. This article presents one approach to building a working-day calculator for use in .NET.
This tutorial will teach you the special effect of super speed similar to the fictional character Wally West aka "The Flash" After Shake : http://www.videocopilot.net/presets/after_shake/ All lightning effects with instructions : http://www.mediaf…
In response to a need for security and privacy, and to continue fostering an environment members can turn to for support, solutions, and education, Experts Exchange has created anonymous question capabilities. This new feature is available to our Pr…

661 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