Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

database insert using MS Application block ExecuteNonQuery method

Posted on 2004-08-16
2
Medium Priority
?
420 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 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

How to Use the Help Bell

Need to boost the visibility of your question for solutions? Use the Experts Exchange Help Bell to confirm priority levels and contact subject-matter experts for question attention.  Check out this how-to article for more information.

Question has a verified solution.

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

Summary: Persistence is the capability of an application to store the state of objects and recover it when necessary. This article compares the two common types of serialization in aspects of data access, readability, and runtime cost. A ready-to…
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…
This Micro Tutorial will teach you how to add a cinematic look to any film or video out there. There are very few simple steps that you will follow to do so. This will be demonstrated using Adobe Premiere Pro CS6.
Look below the covers at a subform control , and the form that is inside it. Explore properties and see how easy it is to aggregate, get statistics, and synchronize results for your data. A Microsoft Access subform is used to show relevant calcul…

927 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