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
- Imports System.Data
- Imports System.Configuration
- Imports System.Data.SqlClient
- Partial Class commision1
- Inherits System.Web.UI.Page
- Public strConnection As String
- Public Conn As SqlConnection
- Public Sql As String
- Public AdditionalSQL As String
- Protected Sub btncommission_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles btncommission.Click
- If Page.IsValid Then
- Dim cmdItem As New SqlCommand
- Dim Rs As Decimal = txtRs.Text
- Dim Date1 As Date = txtDate1.Text
- cmdItem.Connection = GetConnection()
- cmdItem.CommandType = CommandType.StoredProcedure
- cmdItem.CommandText = "sp_RsAdd"
- Dim paramRs As New SqlParameter("@Rs", SqlDbType.Decimal)
- paramRs.Value = Convert.ToDecimal(Rs)
- cmdItem.Parameters.Add(paramRs)
- Dim paramDate1 As New SqlParameter("@Date1", SqlDbType.DateTime)
- paramDate1.Value =Date1.ToString
- cmdItem.Parameters.Add(paramDate1)
- cmdItem.ExecuteNonQuery()
- End If
- End Sub
- Public Function GetConnection() As SqlConnection
- strConnection = ConfigurationManager.AppSettings.Get("ConnectString")
- Conn = New SqlConnection(strConnection)
- Conn.Open()
- Return Conn
- End Function
- End Class
Expand|Select|Wrap|Line Numbers
- set ANSI_NULLS ON
- set QUOTED_IDENTIFIER ON
- go
- ALTER Procedure [dbo].[sp_RsAdd]
- @Rs decimal(2,2),
- @Date1 datetime
- as
- Begin
- INSERT INTO Rs (Rs, Date1)
- VALUES (@rs, @Date1)
- End
Error converting data type numeric to decimal.