473,387 Members | 3,821 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,387 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 2139
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: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
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: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
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: 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
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...

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.