Solved

database insert using MS Application block ExecuteNonQuery method

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

Technology Partners: 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

Article by: Ivo
C# And Nullable Types Since 2.0 C# has Nullable(T) Generic Structure. The idea behind is to allow value type objects to have null values just like reference types have. This concerns scenarios where not all data sources have values (like a databa…
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…
The Email Laundry PDF encryption service allows companies to send confidential encrypted  emails to anybody. The PDF document can also contain attachments that are embedded in the encrypted PDF. The password is randomly generated by The Email Laundr…
A short tutorial showing how to set up an email signature in Outlook on the Web (previously known as OWA). For free email signatures designs, visit https://www.mail-signatures.com/articles/signature-templates/?sts=6651 If you want to manage em…

749 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