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

SqlCommand Problem

Hello

I have a stored procedure with several parameters and 2
are declared datatype Numeric as per the SQL table.

When i try to use the following:

Me.SqlCommand1.CommandType = CommandType.StoredProcedure
Me.SqlCommand1.Parameters.Clear()
Me.SqlCommand1.CommandText = "altera_linha_encomenda"

With Me.SqlCommand1.Parameters
<snip>
.Add("@punit", SqlDbType.Decimal).Value = punit
.Add("@prazo", SqlDbType.Decimal).Value = prazo
End With
Try
Me.SqlCommand1.ExecuteNonQuery()
Catch
MessageBox.Show(Err.Description)
End Try

I get an exception : Error converting data type numeric
to numeric.

I tried to use DeriveParameters on the stored procedure
and punit is declared as numeric(9,2) was converted to
decimal with scale 9 , precision 2 and size 0.

I tried the following :
..Add("@punit", SqlDbType.Decimal, 0).Value = punit
..Add("@punit", SqlDbType.Decimal, 9).Value = punit
..Add("@punit", SqlDbType.Decimal, 2).Value = punit
..Add("@punit", SqlDbType.Decimal, 11).Value = punit

And still I get an execption : Error converting data type
numeric to numeric.

I am running out of ideas, any suggestion would me most
welcome, thanks.

Kind Regards
Jorge

Nov 20 '05 #1
4 2140
Well i found an a solution i don't why the .add doesnt
work with numeric(9,2). This way i have to care about
assignig the values of the parameters.

Me.SqlCommand1.CommandType = CommandType.StoredProcedure
Me.SqlCommand1.Parameters.Clear()
Me.SqlCommand1.CommandText = "altera_linha_encomenda"
Dim objCommandBuilder As New SqlCommandBuilder
Dim p As New SqlParameter
objCommandBuilder.DeriveParameters(SqlCommand1)

For Each p In Me.SqlCommand1.Parameters
If p.ParameterName = "@numenc" Then p.Value =
Me.TextBox1.Text
If p.ParameterName = "@pos" Then p.Value =
posicao_enc_
If p.ParameterName = "@quant" Then p.Value =
Me.TextBox51.Text
If p.ParameterName = "@codigo" Then p.Value =
Me.TextBox52.Text
If p.ParameterName = "@nvias" Then p.Value =
Me.TextBox53.Text
If p.ParameterName = "@id" Then p.Value =
Me.TextBox63.Text
If p.ParameterName = "@punit" Then p.Value = punit
If p.ParameterName = "@obs" Then p.Value =
Me.TextBox16.Text
If p.ParameterName = "@zona" Then p.Value =
Me.TextBox50.Text
If p.ParameterName = "@cor" Then p.Value =
Me.ComboBox7.Text
If p.ParameterName = "@prazo" Then p.Value = prazo
If p.ParameterName = "@tipo" Then p.Value
= "'tipo'"
If p.ParameterName = "@refcli" Then p.Value =
Me.TextBox15.Text
If p.ParameterName = "@idcli" Then p.Value =
Me.TextBox60.Text

Next
-----Original Message-----
Hello

I have a stored procedure with several parameters and 2
are declared datatype Numeric as per the SQL table.

When i try to use the following:

Me.SqlCommand1.CommandType = CommandType.StoredProcedure
Me.SqlCommand1.Parameters.Clear()
Me.SqlCommand1.CommandText = "altera_linha_encomenda"

With Me.SqlCommand1.Parameters
<snip>
.Add("@punit", SqlDbType.Decimal).Value = punit
.Add("@prazo", SqlDbType.Decimal).Value = prazo
End With
Try
Me.SqlCommand1.ExecuteNonQuery()
Catch
MessageBox.Show(Err.Description)
End Try

I get an exception : Error converting data type numeric
to numeric.

I tried to use DeriveParameters on the stored procedure
and punit is declared as numeric(9,2) was converted to
decimal with scale 9 , precision 2 and size 0.

I tried the following :
..Add("@punit", SqlDbType.Decimal, 0).Value = punit
..Add("@punit", SqlDbType.Decimal, 9).Value = punit
..Add("@punit", SqlDbType.Decimal, 2).Value = punit
..Add("@punit", SqlDbType.Decimal, 11).Value = punit

And still I get an execption : Error converting data typenumeric to numeric.

I am running out of ideas, any suggestion would me most
welcome, thanks.

Kind Regards
Jorge

.

Nov 20 '05 #2
Well i found an a solution i don't why the .add doesnt
work with numeric(9,2). This way i have to care about
assignig the values of the parameters.

Me.SqlCommand1.CommandType = CommandType.StoredProcedure
Me.SqlCommand1.Parameters.Clear()
Me.SqlCommand1.CommandText = "altera_linha_encomenda"
Dim objCommandBuilder As New SqlCommandBuilder
Dim p As New SqlParameter
objCommandBuilder.DeriveParameters(SqlCommand1)

For Each p In Me.SqlCommand1.Parameters
If p.ParameterName = "@numenc" Then p.Value =
Me.TextBox1.Text
If p.ParameterName = "@pos" Then p.Value =
posicao_enc_
If p.ParameterName = "@quant" Then p.Value =
Me.TextBox51.Text
If p.ParameterName = "@codigo" Then p.Value =
Me.TextBox52.Text
If p.ParameterName = "@nvias" Then p.Value =
Me.TextBox53.Text
If p.ParameterName = "@id" Then p.Value =
Me.TextBox63.Text
If p.ParameterName = "@punit" Then p.Value = punit
If p.ParameterName = "@obs" Then p.Value =
Me.TextBox16.Text
If p.ParameterName = "@zona" Then p.Value =
Me.TextBox50.Text
If p.ParameterName = "@cor" Then p.Value =
Me.ComboBox7.Text
If p.ParameterName = "@prazo" Then p.Value = prazo
If p.ParameterName = "@tipo" Then p.Value
= "'tipo'"
If p.ParameterName = "@refcli" Then p.Value =
Me.TextBox15.Text
If p.ParameterName = "@idcli" Then p.Value =
Me.TextBox60.Text

Next
-----Original Message-----
Hello

I have a stored procedure with several parameters and 2
are declared datatype Numeric as per the SQL table.

When i try to use the following:

Me.SqlCommand1.CommandType = CommandType.StoredProcedure
Me.SqlCommand1.Parameters.Clear()
Me.SqlCommand1.CommandText = "altera_linha_encomenda"

With Me.SqlCommand1.Parameters
<snip>
.Add("@punit", SqlDbType.Decimal).Value = punit
.Add("@prazo", SqlDbType.Decimal).Value = prazo
End With
Try
Me.SqlCommand1.ExecuteNonQuery()
Catch
MessageBox.Show(Err.Description)
End Try

I get an exception : Error converting data type numeric
to numeric.

I tried to use DeriveParameters on the stored procedure
and punit is declared as numeric(9,2) was converted to
decimal with scale 9 , precision 2 and size 0.

I tried the following :
..Add("@punit", SqlDbType.Decimal, 0).Value = punit
..Add("@punit", SqlDbType.Decimal, 9).Value = punit
..Add("@punit", SqlDbType.Decimal, 2).Value = punit
..Add("@punit", SqlDbType.Decimal, 11).Value = punit

And still I get an execption : Error converting data typenumeric to numeric.

I am running out of ideas, any suggestion would me most
welcome, thanks.

Kind Regards
Jorge

.

Nov 20 '05 #3

I tried the following :
.Add("@punit", SqlDbType.Decimal, 0).Value = punit

i think the error is occurring during your conversion of punit to decimal
type
what is punit...

are you sure you want the decimal type?

i've never used it

brad
Nov 20 '05 #4

I tried the following :
.Add("@punit", SqlDbType.Decimal, 0).Value = punit

i think the error is occurring during your conversion of punit to decimal
type
what is punit...

are you sure you want the decimal type?

i've never used it

brad
Nov 20 '05 #5

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

10
by: Henrik Dahl | last post by:
Hello! After I've finished using an instance of the SqlCommand class, should I then invoke Dispose() on the instance. I suppose so, as there is a Dispose method, but what does it actually...
6
by: BuddyWork | last post by:
Does anyone know if there are any articles explaining how I could debug into SqlCommand.ExecuteReader so I can see why I am getting a particular error. thanks
2
by: Andre Ranieri | last post by:
I'm having trouble with what should be a simple task; beginning and committing T-SQL transactions using the SQLClient. I'm using a SqlCommand (cmd) to begin the transaction and delete records from...
5
by: JIM.H. | last post by:
Hello, I could not call this sub routine because it says SqlConnection and SqlCommand is not defined. Public Sub CreateMySqlCommand(ByVal myExecuteQuery As String, ByVal myConnection As...
10
by: John Bailo | last post by:
I want to pass a SqlCommand object as a input parameter to a method. I want to pass the SqlCommand "by value" so that any updates to the original object are *not* reflected in the object within...
1
by: job | last post by:
how is it possible to serialize/de-serialize a SqlCommand?
0
by: Leanne | last post by:
I am doing customization for Microsoft Pos. I am working on installation package now. I added some new tables and stored procuedures and generated SQL Script for that. During the installation...
6
by: Nuzzi | last post by:
Hello All, I have two pages that are very similar. One is working, one is not. Here is the code for both: Page 1 (Working): protected void btn_update_Click(object sender, EventArgs e)...
6
by: Frank Hauptlorenz | last post by:
Hello, I'm trying to send an SqlCommand to a WCF-Service. For this I'm using the following DataContract: public class SqlCommandComposite { SqlCommand cmd = new SqlCommand();
2
by: Austin326 | last post by:
Hi Everyone, I have a problem that is quite frusturating. I am passing in an image from a database, which is to be accessed in an image button. When I dynamically add the string for an sql...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
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:
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
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
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.