Error Converting Data Type Nvarchar To Int In Asp.net
here for a quick overview of the site Help Center Detailed answers to any questions you might have Meta Discuss the workings and policies of this site About Us Learn more about Stack Overflow the company Business Learn more about hiring developers or posting ads with us Stack Overflow Questions Jobs Documentation Tags Users Badges Ask Question x Dismiss Join the Stack Overflow Community Stack Overflow is a community of 4.7 million programmers, just like you, helping each other. Join them; it only takes a minute: Sign up “Error converting data type nvarchar to int.” executing stored procedure up vote 0 down vote favorite I have a stored procedure and I am getting this error when executing it from C# code. Error converting data type nvarchar to int. My stored procedure: CREATE PROCEDURE [dbo].[donateBloodProc] @donorName varchar(50), @gender varchar(20), @email varchar(50), @bloodGroup varchar(50), @contact_number int, @L_D_D date, @city varchar(50), @arid_number varchar(50), @DepId int AS INSERT INTO tblDonors(Dname, gender, bloodGroup, email, contact_number, L_D_D,city,arid_number,DeptID,dateDonated) VALUES (@donorName,@gender,@bloodGroup,@email,@contact_number, @L_D_D,@city,@arid_number,@DepId,GETDATE()); And this is my C# code: SqlCommand commandForSP = new SqlCommand("donateBloodProc",DALobj.openConnection()); commandForSP.CommandType = System.Data.CommandType.StoredProcedure; commandForSP.Parameters.AddWithValue("@donorName", TextBox1.Text); commandForSP.Parameters.AddWithValue("@gender", RadioButtonList1.SelectedValue); commandForSP.Parameters.AddWithValue("@email", TextBox5.Text); commandForSP.Parameters.AddWithValue("@bloodGroup", DropDownList1.SelectedValue); commandForSP.Parameters.AddWithValue("@contact_number", TextBox2.Text); commandForSP.Parameters.AddWithValue("@L_D_D", TextBox3.Text); commandForSP.Parameters.AddWithValue("@city", DropDownList2.SelectedValue); commandForSP.Parameters.AddWithValue("@arid_number", TextBox1.Text); commandForSP.Parameters.AddWithValue("@DepId", TextBox4.Text); commandForSP.ExecuteNonQuery(); All the data types of the columns in my stored procedure are same as in my database table tblDonors c# asp.net sql-server asp.net-mvc stored-procedures share|improve this question edited Feb 15 '14 at 9:09 marc_s 452k938641029 asked Feb 15 '14 at 8:11 user1494459 add a comment| 2 Answers 2 active oldest votes up vote 0 down vote The problem is with these lines: commandForSP.Parameters.AddWithValue("@contac
ASP.NET Community Standup Forums Help Home/ASP.NET Forums/Data Access/ADO.NET, Entity Framework, LINQ to SQL, NHibernate/Error converting data type nvarchar to int. Error converting data type nvarchar to int. [Answered]RSS 11 replies Last post Jun 02, 2011 11:08 AM by funluckykitty ‹ Previous Thread|Next Thread › Print Share Twitter Facebook Email Shortcuts Active Threads Unanswered Threads Unresolved Threads Support Options Advanced Search Reply funluckykitt... Participant 1089 Points 1631 Posts Error converting data type nvarchar to int. Jun 01, 2011 02:19 PM|funluckykitty|LINK Argh... I keep getting this error when trying to execute my sql insert stored procedure, BUT only http://stackoverflow.com/questions/21795045/error-converting-data-type-nvarchar-to-int-executing-stored-procedure if the user doesn't make a selection in a drop down box. This is driving me nuts. :-( If they don't make a selection in the ddNewBillingAttorney drop down box, I pass in a parameter value for a hidden field (This is when it fails). If they do make a selection in the dropdown box, I pass in whatever they selected. Why does this fail when http://forums.asp.net/t/1686007.aspx?Error+converting+data+type+nvarchar+to+int+ I try to pass in the value for the hidden field? Here's a snipped of my code from my code behind: If ddNewBillingAttorney.SelectedIndex = "0" Then comm.Parameters.AddWithValue("InitiatingAttorneyID", (hdnExistingBillingAttorneyID.Value)) <-- If they didn't make a selection, send the value for the hidden field, and this is the part that fails. Else comm.Parameters.AddWithValue("InitiatingAttorneyID", ddNewBillingAttorney.SelectedValue) <--If they do make a selection, the insert works just fine. End If --Susan Reply nobdy Contributor 3720 Points 1014 Posts Re: Error converting data type nvarchar to int. Jun 01, 2011 03:29 PM|nobdy|LINK Try this.. If ddNewBillingAttorney.SelectedIndex = 0 Then Let me know if this works. If this post was useful to you, please Mark it as Answer. Reply funluckykitt... Participant 1089 Points 1631 Posts Re: Error converting data type nvarchar to int. Jun 01, 2011 04:19 PM|funluckykitty|LINK My problem isn't with the if/then portion of the statement. It seems to be with sending the parameter for the hidden field as an integer. I keep getting "error converting data type nvarchar to int on the paramater. --Susan Reply MetalAsp.Net All-Star 101939 Points 20711 Posts Moderator Re: Error converting data type nvarchar to int. Jun 01, 2011 04:22 PM|MetalAsp.Net|LINK It looks like I
Tips/Tricks Top Articles Beginner Articles Technical Blogs Posting/Update Guidelines Article Help Forum Article Competition Submit an article or tip Post your Blog http://www.codeproject.com/Questions/241806/Cannot-Convert-Datatype-nvarchar-into-int-error quick answersQ&A Ask a Question View Unanswered Questions View All Questions... C# http://www.c-sharpcorner.com/forums/sqlexception-error-converting-data-type-nvarchar-to-int questions Linux questions ASP.NET questions SQL questions VB.NET questions discussionsforums All Message Boards... Application Lifecycle> Running a Business Sales / Marketing Collaboration / Beta Testing Work Issues Design and Architecture ASP.NET JavaScript C / C++ / MFC> ATL / WTL / STL Managed C++/CLI C# error converting Free Tools Objective-C and Swift Database Hardware & Devices> System Admin Hosting and Servers Java .NET Framework Android iOS Mobile SharePoint Silverlight / WPF Visual Basic Web Development Site Bugs / Suggestions Spam and Abuse Watch features Competitions News The Insider Newsletter The Daily Build Newsletter Newsletter archive Surveys Product Showcase Research Library CodeProject Stuff communitylounge error converting data Who's Who Most Valuable Professionals The Lounge The Insider News The Weird & The Wonderful The Soapbox Press Releases Non-English Language > General Indian Topics General Chinese Topics help What is 'CodeProject'? General FAQ Ask a Question Bugs and Suggestions Article Help Forum Site Map Advertise with us About our Advertising Employment Opportunities About Us Ask a Question All Questions All Unanswered FAQ Cannot Convert Datatype nvarchar into int error Rate this: Please Sign up or sign in to vote. See more: C#3.5 Hi, This is my Insert Button Code: private void button3_Click(object sender, EventArgs e) { try { cmd.Parameters.Clear(); cmd.CommandText = "Ins_Upd_Students";//Ins_Upd_Students is my stored procedure cmd.Parameters.AddWithValue("@Sno", textBox1.Text); cmd.Parameters.AddWithValue("@Sname", textBox2.Text); cmd.Parameters.AddWithValue("@Class", textBox3.Text); cmd.Parameters.AddWithValue("@Fees", textBox4.Text); con.Open(); int affectedRecord=cmd.ExecuteNonQuery(); MessageBox.Show("Executed"); } catch (Exception ex) { MessageBox.Show(ex.Message); } finally { con.Close(); } } I declared all my table column as varchar(50) type. At the time of insertion it shows the error as cannot convert data type nvarchar into int. Can any one tel me why I'm getting t
DOWNLOAD: C# Corner Android App Version 0.5.3 Released C# Corner Annual Conference 2017 Announced Forums - C# Corner C# Corner Home Technologies Monthly Leaders ASK A QUESTION C# Programming Multi-threading IoT Coffee, Chai Lounge HTML, JavaScript, CSS .NET General Office Interoperability Microsoft Surface Community Services iPhone, iPad Active Directory Printing ReFS Current Affairs Java ADO.NET & Database Project Management Silverlight 5 Fun and Jokes JQuery AJAX & Atlas Remoting WCF Job Opportunities JSP Algorithms & AI Reporting Windows 8 Leadership Multimedia, Graphics, Flash Arrays & Collections Robotics and Hardware Windows Azure Mac for Windows Node.js ASP.NET & Web Development Security & Cryptography Windows Store Apps Microsoft Feedback PHP C# Language Setup & Deployment Workflow Foundation Open Source Projects Social Networking C# References Sharepoint WPF Operating Systems TypeScript CLR & .NET Internals Speech & Voice Recognition XAML Language Paid Projects Web Hosting COM Interoperability Tablet PC Site and Forums Feedback Prizes, Awards, MVP Website Management Custom Controls Testing and QA Announcements Students & Beginner Projects Windows Phone 7 Design and Architecture Visual Basic .NET Author Guidelines Test Category Database Embedded Development Visual C++ Bugs and Problems Training & Certification Database General Enterprise Development Visual Studio 11 Forums Feedback Web Development Oracle Games, DirectX, and XNA Visual Studio 2010 Site Feedback & Suggestions Advertising, Marketing, SEO SQL GDI+ and DirectX Web Services Site Spams Android SQL Server General Windows Forms Miscellaneous AngularJS Products LINQ Windows Services .NET Books Cloud Computing Office 2013 Migrating to .NET Cutting-Edge Ask the Author Expression Tools Products Mobile Development .NET 5.0 Career Advice HTML 5 SharePoint 2013 Forum guidelines Home ADO.NET & Database SqlException :Error converting data type nvarchar to int vishal mewara 1.3k 12 14.1k SqlException :Error converting data type nvarchar to int Mar 8 2014 8:40 AM Default.aspx <%@ Page Language="C#" AutoEventWireup="true" CodeFile="Default.aspx.cs" Inherits="_Default" %> First Name: Email Address: Gender: Male Female Mobile Number: