Control Panel
Forum
Hosting Help
ASP.NET 4 & SQL 2008 Hosting
Resources
Notice
Login
Members
Shared Hosting
|
New Features
|
Advertise
|
Tutorials
|
Silverlight Tutorials
|
Product Reviews in India
|
Free aptitude test questions
|
TATA Nano Car reviews
Total
members
:
149203
Average new registrations per day (in last 7 days):
122
New Registration:
Open
Register Now
Learn Windows 7:
Windows 7 control panel options and settings
Control Panel is one of the most important elements of Windows 7, even more than with previous versions of this operating system. The Panel, a renowned computer settings, provides access to all elements of monitoring, development, customization, security and Windows development. In other words, learning to control it is mandatory to really enjoy his computer.So,learn here to access your contro panel in windows 7.
Want to become a DBA ?
SQL Server 2008 training courses
- by AspSpider team
Home
»
Questions & Answers
»
Conversion from string to type integer is not valid.. PLEASE...
Conversion from string to type integer is not valid.. PLEASE HELP ME!! (tHANKS IN ADVANCE)
3/10/2010
Author:
carlito miralles
Technological Institute of The Philippines
I CANNOT INSERT A NEW RECORD DUE TO AN ERROR MESSAGE FOR Conversion from string to type integer is not valid
HERE IS THE CODE FOR VB.NET
strParamName = New String() {ClientName}
strParamDataType = New String() {String}
strParamSQLDbType = New SqlDbType() {SqlDbType.NVarChar}
strParamLength = New String() {50}
strParamValue = New String() {txtClientName.Text}
Dim intCheck As Integer = CheckForExistingData(spQueryClientExist, Check Existing Client Data, False, mClientName, )
If intCheck = 1 Then
MsgBox(There is already an existing record for the client name you specified!, MsgBoxStyle.Information, Me.Text)
ElseIf intCheck = 0 Then
strParamName = New String() {ClientName, ClientID, @Status} 'Client_ID
strParamDataType = New String() {String, Int, Int} 'String
strParamSQLDbType = New SqlDbType() {SqlDbType.Char, SqlDbType.Int, SqlDbType.Int}
strParamLength = New String() {50, 0, 0}
strParamValue = New String() {txtClientName.Text, txtClientID.Text, 0}
If Me.Text = New Client Then
If UpdateRecord(spWebInsertClientAccountReturnClientId, Add New Client, Added New Client - & txtClientName.Text) Then 'spInsertClient spWebInsertClientAccountReturnClientId
isRefresh = True
Me.Close()
End If
Else
If UpdateRecord(spWebUpdateClientAccount, Update Existing Client, Modified Client Name - & txtClientName.Text) Then 'spUpdateClient' spWebUpdateClientAccount
isRefresh = True
Me.Close()
End If
End If
End If
==========================
AND THE STORE PROCEDURE IN MY DATABASE IS
set ANSI_NULLS ON
set QUOTED_IDENTIFIER ON
GO
ALTER PROCEDURE [dbo].[spInsertClient]
@Client_ID INT,
@ClientName NVARCHAR(50)
AS
BEGIN
INSERT INTO tblClientAccount
(Client_Name)
VALUES
(@ClientName)
END
+++++++++++++++++++++
PLEASE HELP ME..
THANK YOU.. :-)
Answers .............
Author:
Ahmed Talu
Posted Date: 3/15/2010
*************************************************
carlito miralles
When converting a number that appear as one or more characters in a string to another form such as an integer then it is common to PARSE the content of the string using built-in parsing. Parsing is a feature that is available in a number of programming languages (including VB and C#). Parsing can extract a number from a string by figuring out what character(s) in a string represents a valid number. In particular a valid number that can be represented in a specific type of object other than a string. The specific type of object depends on the kind of number desired.
In your case, to convert the number make one STRING type object (say AAAA) and one INTEGER type object (say BBBB). Parse the string and store the result of the parsing in the integer. When making the prepare for strings that do not contain valid numbers so such strings can be handled in a manner acceptable for the application.
Is it the string strParamDataType that you want to convert?
*************************************************
By the way, parsing can also be used for other purposes than extracting numbers. This includes splitting strings into several parts.
*************************************************
VB.aspx
*************************************************
<%@ Page Language="VB" ContentType="Text/Plain" ResponseEncoding="utf-8" %>
HTML tags are included for use in the event of ContentType="Text/html"
<html> <head>
<title>This sample was found in the forum at ASPSPIDER (http://www.aspspider.com/ ).</title>
</head><body><p>
<%
Dim AAAA As String
Dim BBBB As Integer
AAAA = "12345"
BBBB = Integer.Parse(AAAA)
Dim CCCC As Integer = Integer.Parse(AAAA)
Response.Write("Test if parsing works (BBBB): " + BBBB.ToString + " <br>" + Chr(10) + "Test if parsing works (CCCC): " + CCCC.ToString)
%>
<%--
' Beware that in VB whitespace following the last pair of <% %> is not sent in the response if there is no non-whitespace characters there. However, if there is any non-whitespace character there then all whitespace are sent (even whitespace following the last non-whitespace character). This is different from C#.
' As for the whitespace above the first pair of <% %> (or between one pair of <% %> and another pair of <% %>) then this whitespace is sent in the response if the space contains at least one non-whitespace character. If there isn't any non-whitespace characters then the whitespace is not sent. This is the same as in C#.
--%>
</p></body>
</html>
*************************************************
CS.aspx
*************************************************
<%@ Page Language="C#" ContentType="Text/Plain" ResponseEncoding="utf-8" %>
HTML tags are included for use in the event of ContentType="Text/html"
<html> <head>
<title>This sample was found in the forum at ASPSPIDER.</title>
</head><body><p>
<%
String AAAA;
int BBBB;
AAAA = "12345";
BBBB = int.Parse(AAAA);
int CCCC = int.Parse(AAAA);
Response.Write("Test if parsing works (BBBB): ");
Response.Write(BBBB);
Response.Write(" <br>\nTest if parsing works (CCCC): ");
Response.Write(CCCC);
%>
<%--
Beware that in C# whitespace following the last pair of <% %> is sent in the response regardless of whether there is any text or not. This is different from VB.
As for the whitespace above the first pair of <% %> (or between one pair of <% %> and another pair of <% %>) then this whitespace is sent in the response if the space contains at least one non-whitespace character. If there isn't any non-whitespace characters then the whitespace is not sent. This is the same as in VB.
--%>
ASPSPIDER.NET - now located at http://www.aspspider.com/
</p></body>
</html>
*************************************************
Please inform below if the above is of any help to you. Have I understood your problem correctly (I have not looked into the matter of SQL insertion, only converting a string to a number like an integer)?
*************************************************
You must
login
to post answer for this question.
Advertise
Privacy Policy
Terms of use
Contact Us
SpiderWorks Technologies Pvt Ltd.
All Rights Reserved.