473,409 Members | 1,952 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,409 software developers and data experts.

problem with data type

44
Hi

I have to insert the commision value and date into the database. For that I have given the coding as
Expand|Select|Wrap|Line Numbers
  1.  
  2. Imports System.Data
  3. Imports System.Configuration
  4. Imports System.Data.SqlClient
  5. Partial Class commision1
  6. Inherits System.Web.UI.Page
  7. Public strConnection As String
  8.  
  9. Public Conn As SqlConnection
  10. Public Sql As String
  11. Public AdditionalSQL As String
  12.  
  13. Protected Sub btncommission_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles btncommission.Click
  14. If Page.IsValid Then
  15. Dim cmdItem As New SqlCommand
  16. Dim commision As String = txtCommission.Text
  17. Dim EffectiveDate As String = txtDate.Text
  18.  
  19. cmdItem.Connection = GetConnection()
  20.  
  21. cmdItem.CommandType = CommandType.StoredProcedure
  22. cmdItem.CommandText = "sp_CommisionAdd"
  23.  
  24. Dim paramcommision As New SqlParameter("@commision", SqlDbType.Decimal)
  25. paramcommision.Value = commision
  26. cmdItem.Parameters.Add(commision)
  27.  
  28. Dim paramEffectiveDate As New SqlParameter("@EffectiveDate", SqlDbType.SmallDateTime)
  29. paramEffectiveDate.Value = EffectiveDate
  30. cmdItem.Parameters.Add(paramEffectiveDate)
  31. cmdItem.ExecuteNonQuery()
  32.  
  33. End If
  34. End Sub
  35. Public Function GetConnection() As SqlConnection
  36. strConnection = ConfigurationManager.AppSettings.Get("ConnectString")
  37. Conn = New SqlConnection(strConnection)
  38. Conn.Open()
  39. Return Conn
  40. End Function
  41. End Class
  42.  
In sql server 2005 I have a table named commision with feilds as

Commision decimal(2,2)
EffectiveDate smalldatetime


but while running I am getting the error as

The SqlParameterCollection only accepts non-null SqlParameter type objects, not String objects.
Jul 30 '08 #1
4 1467
sweatha
44
Hi

Then I replaced the lines

Dim commision As String = txtCommission.Text
Dim EffectiveDate As String = txtDate.Text

as

Dim commision As Decimal = txtCommission.Text
Dim EffectiveDate As Date = txtDate.Text

but while running the error is

The SqlParameterCollection only accepts non-null SqlParameter type objects, not Decimal objects.
Jul 30 '08 #2
DrBunchman
979 Expert 512MB
Hi sweatha,

I think there's a problem on line 25. You define your SQLParameter but then instead of adding that you add the variable commission to your SQLCommand.

Hope this helps,

Dr B
Jul 30 '08 #3
sweatha
44
Hi

I have changed the line no 25 as

cmdItem.Parameters.Add(paramcomm)

But still I got the error as

Error converting data type numeric to decimal.
Jul 31 '08 #4
DrBunchman
979 Expert 512MB
I'd have thought this one was self explanatory!

It's telling you what the error is - you are trying to pass a variable of type Numeric to one of type Decimal. Check that the data type of your sql parameter, your sql parameter object and the variable you are passing in to it all match.

Dr B
Jul 31 '08 #5

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

Similar topics

0
by: john | last post by:
Hi,All Gurus: It is kind of complicated, please bear with me and let me know if you have any questions. Thanks a lot in advance. John I have a csharp method, using emit to dynamically generate...
0
by: Lokkju | last post by:
I am pretty much lost here - I am trying to create a managed c++ wrapper for this dll, so that I can use it from c#/vb.net, however, it does not conform to any standard style of coding I have seen....
4
by: Alex Sibilev | last post by:
Hello, I have a really weird problem I've been trying to solve it without any luck for the last couple of hours :( I'm writing a "conference board" application (quite similar to ASP.NET...
2
by: ajikoe | last post by:
Hi, I tried to follow the example in swig homepage. I found error which I don't understand. I use bcc32, I already include directory where my python.h exist in bcc32.cfg. /* File : example.c...
2
by: DC | last post by:
The Code <%@ import namespace="System" %> <%@ import namespace="System.Web" %> <%@ import namespace="System.Web.UI" %> <%@ import namespace="System.Web.UI.HtmlControls" %> <%@ import...
2
by: Ch Pravin | last post by:
Hi All: I am having the following xml which i need to convert to excel using xslt. Please help me out. Afghanistan.xml <?xml version="1.0" encoding="utf-16"?> <Languages...
5
by: 2beagles | last post by:
I have a template for a three dimensional array that I have been working on using Visual C++ 6.0. Under version 6 this code worked fine. However, last night I downloaded Visual C++ 2005 Express and...
10
by: kkirtac | last post by:
Hi, i have a void pointer and i cast it to an appropriate known type before using. The types which i cast this void* to are, from the Intel's open source computer vision library. Here is my piece...
10
by: oktayarslan | last post by:
Hi all; I have a problem when inserting an element to a vector. All I want is reading some data from a file and putting them into a vector. But the program is crashing after pushing a data which...
4
pradeepjain
by: pradeepjain | last post by:
i had posted the same code in javascript area !! this i am posting bcos of different problem. as you can see in ma code there is a dropdown called sort ...its sorts the result by the value he...
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
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
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:
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
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
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
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...

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.