0

I am doing a Smart device project The problam is I can not pass parameters to the stored procedure to insert into the database from the PDA emulator for the following sqlDbtypes it gives me the following error

A first chance exception of type 'System.InvalidOperationException' occurred in System.Data.SqlClient.dll

Deicimal
Money
Int
Numeric

these sqlDBtypes work fine when I pass the parameters to the same stored procedure with a windows application( not smart device application). the database gets uupdated correctly.

This is my Code block

public void opendb()
        {
            String connStr = "Data Source=192.168.1.1,1433;Initial Catalog=Resmanagement;User ID=sa;Password=thadiya;";
            myConn1 = new SqlConnection(connStr);

            myConn1.Open();
        }

        public void closedb()
        {
            if (myConn1 != null)
            {
                myConn1.Close();
            }

        }

        private void button1_Click(object sender, EventArgs e)
        {
            dblPrice = 1000;

            try
            {
                opendb();

                SqlCommand command1 = new SqlCommand("Test2", myConn1);
                command1.CommandType = CommandType.StoredProcedure;

                command1.Parameters.Add("@Price", SqlDbType.Decimal,9, "Price").Value =Convert.ToDecimal(dblPrice);

                command1.ExecuteNonQuery();
                command1.Dispose();

                closedb();
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message);
            }


        }

Edited by mike_2000_17: Fixed formatting

1
Contributor
1
Reply
2
Views
6 Years
Discussion Span
Last Post by Don_leon
0

I am doing a Smart device project The problam is I can not pass parameters to the stored procedure to insert into the database from the PDA emulator for the following sqlDbtypes it gives me the following error

A first chance exception of type 'System.InvalidOperationException' occurred in System.Data.SqlClient.dll

Deicimal
Money
Int
Numeric

these sqlDBtypes work fine when I pass the parameters to the same stored procedure with a windows application( not smart device application). the database gets uupdated correctly.

This is my Code block

public void opendb()
        {
            String connStr = "Data Source=192.168.1.1,1433;Initial Catalog=Resmanagement;User ID=sa;Password=thadiya;";
            myConn1 = new SqlConnection(connStr);

            myConn1.Open();
        }

        public void closedb()
        {
            if (myConn1 != null)
            {
                myConn1.Close();
            }

        }

        private void button1_Click(object sender, EventArgs e)
        {
            dblPrice = 1000;

            try
            {
                opendb();

                SqlCommand command1 = new SqlCommand("Test2", myConn1);
                command1.CommandType = CommandType.StoredProcedure;

                command1.Parameters.Add("@Price", SqlDbType.Decimal,9, "Price").Value =Convert.ToDecimal(dblPrice);

                command1.ExecuteNonQuery();
                command1.Dispose();

                closedb();
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message);
            }


        } 

end quote.

new corrections

command1.Parameters.Add("@Price", SqlDbTypey.Money,8, "Price").Value=Convert.ToDecimal(dblPrice);

table Defenition(Table name test)---------Price   DataType(money)

Edited by mike_2000_17: Fixed formatting

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.