1. This site uses cookies. By continuing to use this site, you are agreeing to our use of cookies. Learn More.

Can Not Pass params to Stored Procedures in my Smard device project

Discussion in 'C#' started by Don_leon, Sep 11, 2010.

  1. Don_leon

    Don_leon New Member

    Joined:
    Sep 11, 2010
    Messages:
    1
    Likes Received:
    0
    Trophy Points:
    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

    Code:
    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);
                }
    
    
            }
     

Share This Page