473,396 Members | 2,052 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,396 software developers and data experts.

Conversion Problem

39
Hi

I have to insert two textbox values into the database. In sql server 2005, I have the table named Rs with the following fields

Rs decimal(2, 2)
date1 datetime

In front end I have given the coding as

Expand|Select|Wrap|Line Numbers
  1. Imports System.Data
  2. Imports System.Configuration
  3. Imports System.Data.SqlClient
  4. Partial Class commision1
  5.     Inherits System.Web.UI.Page
  6.     Public strConnection As String
  7.  
  8.     Public Conn As SqlConnection
  9.     Public Sql As String
  10.     Public AdditionalSQL As String
  11.  
  12.     Protected Sub btncommission_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles btncommission.Click
  13.         If Page.IsValid Then
  14.             Dim cmdItem As New SqlCommand
  15.             Dim Rs As Decimal = txtRs.Text
  16.             Dim Date1 As Date = txtDate1.Text
  17.  
  18.             cmdItem.Connection = GetConnection()
  19.  
  20.             cmdItem.CommandType = CommandType.StoredProcedure
  21.             cmdItem.CommandText = "sp_RsAdd"
  22.  
  23.             Dim paramRs As New SqlParameter("@Rs", SqlDbType.Decimal)
  24.             paramRs.Value = Convert.ToDecimal(Rs)
  25.             cmdItem.Parameters.Add(paramRs)
  26.  
  27.             Dim paramDate1 As New SqlParameter("@Date1", SqlDbType.DateTime)
  28.             paramDate1.Value =Date1.ToString
  29.             cmdItem.Parameters.Add(paramDate1)
  30.             cmdItem.ExecuteNonQuery()
  31.  
  32.         End If
  33.     End Sub
  34.     Public Function GetConnection() As SqlConnection
  35.         strConnection = ConfigurationManager.AppSettings.Get("ConnectString")
  36.         Conn = New SqlConnection(strConnection)
  37.         Conn.Open()
  38.         Return Conn
  39.     End Function
  40. End Class
The stored procedure I have given is

Expand|Select|Wrap|Line Numbers
  1. set ANSI_NULLS ON
  2. set QUOTED_IDENTIFIER ON
  3. go
  4.  
  5.  
  6.  
  7. ALTER Procedure [dbo].[sp_RsAdd]
  8.     @Rs decimal(2,2),
  9.     @Date1 datetime
  10.  
  11. as
  12. Begin
  13.  
  14. INSERT INTO Rs (Rs, Date1)
  15. VALUES (@rs, @Date1)
  16.  
  17. End
But when I run the project, I get the error as

Error converting data type numeric to decimal.
Jul 31 '08 #1
2 990
Hi..

try converting txtRs.Text into decimal format only.May be the value in the text box is numeric.Hope this should be resolved.
Jul 31 '08 #2
Curtis Rutland
3,256 Expert 2GB
Lines 15 and 16 seem to be your problem. You should explicitly cast the decimal value and the date value using the Convert class.
Jul 31 '08 #3

Sign in to post your reply or Sign up for a free account.

Similar topics

1
by: Vladimir Khvostov | last post by:
Hi, We have some DB2 table on the host that has varchar(3200) columns that are used to store binary data (I know that "varchar(3200) for bit data" should have been used, by modifying host table is...
31
by: Bjørn Augestad | last post by:
Below is a program which converts a double to an integer in two different ways, giving me two different values for the int. The basic expression is 1.0 / (1.0 * 365.0) which should be 365, but one...
11
by: Steve Gough | last post by:
Could anyone please help me to understand what is happening here? The commented line produces an error, which is what I expected given that there is no conversion defined from type double to type...
3
by: Steve Richter | last post by:
here is a warning I am getting in a C++ .NET compile: c:\SrNet\jury\JuryTest.cpp(55) : warning C4927: illegal conversion; more than one user-defined conversion has been implicitly applied while...
0
by: VB Programmer | last post by:
Simple ASP.NET 1 site. Opened solution in beta 2 of 2.0. Ran thru conversion wizard and it states: "Conversion Complete. There were some errors during conversion." I view the conversion log...
4
by: Påhl Melin | last post by:
I have some problems using conversion operators in C++/CLI. In my project I have two ref class:es Signal and SignalMask and I have an conversion function in Signal to convert Signal:s to...
14
by: Richard G. Riley | last post by:
Would it be wrong to use "implicit casting" instead of the standards "implicit conversion" when talking about implicit conversions between certain data types. The standard mentions "explicit...
6
by: Dhirendra Singh | last post by:
Hi, The following C++ program is not compiling on my system. #include <iostream> using namespace std; class complex { double re, im; public: complex( ) :re(0), im(0) {}
4
by: Coleen | last post by:
Hi All :-) I'm new to this site. I've been trying to convert several .Net 2003 web applications and getting tons of conversion errors. I found this site to help walk me through the...
8
by: Nikola | last post by:
Hello, I'm writing a String class for C++ and I'm getting the following error message when using operator: test.cpp: In function ‘int main()’: test.cpp:7: error: ISO C++ says that these are...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.