?
Solved

executing Stored procedure and error

Posted on 2006-11-21
3
Medium Priority
?
238 Views
Last Modified: 2010-05-18
I am trying to execute the bewlo SP when the button1_click
occured, but I am geeting an error in CATCH statment and the number from daabase is not shown in the text box.

The error I am getting: when casting from number, the value must be a numbe less than infinity. Make sure the source type is convertible to the destination type.


public static int Acute_Treatment(int year, int month, string unit_abbr)
    {

        string connectionString = ConfigurationManager.ConnectionStrings["Finance_AppsConnectionString"].ConnectionString;
        System.Data.IDbConnection dbConnection = new System.Data.SqlClient.SqlConnection(connectionString);

        System.Data.IDbCommand dbCommand = new System.Data.SqlClient.SqlCommand();
        dbCommand.CommandText = "usp_Acute_Treatment";
        dbCommand.CommandType = CommandType.StoredProcedure;
        dbCommand.Connection = dbConnection;


        System.Data.IDataParameter dbParam_year = new System.Data.SqlClient.SqlParameter();
        dbParam_year.ParameterName = "@year";
        dbParam_year.Value = year;
        dbParam_year.DbType = System.Data.DbType.Int32;
        dbCommand.Parameters.Add(dbParam_year);



        System.Data.IDataParameter dbParam_month = new System.Data.SqlClient.SqlParameter();
        dbParam_month.ParameterName = "@month";
        dbParam_month.Value = month;
        dbParam_month.DbType = System.Data.DbType.Int32;
        dbCommand.Parameters.Add(dbParam_month);

        System.Data.IDataParameter dbParam_unitabbr = new System.Data.SqlClient.SqlParameter();
        dbParam_unitabbr.ParameterName = "@unit_abbr";
        dbParam_unitabbr.Value = unit_abbr;
        dbParam_unitabbr.DbType = System.Data.DbType.String;
        dbCommand.Parameters.Add(dbParam_unitabbr);
       

        int result = 0;

        try
        {
            dbConnection.Open();
            result = (int)dbCommand.ExecuteScalar();
        }
        catch
        {

        }


        finally
        {
            dbConnection.Close();
        }


        return result;


    }


  protected void Button1_Click(object sender, EventArgs e)
    {

        int month = Convert.ToInt32(DropDownList1.SelectedValue);
        int year = Convert.ToInt32(DropDownList2.SelectedValue);
        string unit_abbr = Convert.ToString(DropDownList3.SelectedValue);



        Acutetxt.Text = Convert.ToString(ActuteTreatments.Acute_Treatment(year, month, unit_abbr));

}
0
Comment
Question by:jung1975
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
3 Comments
 
LVL 18

Accepted Solution

by:
Elvio Lujan earned 1000 total points
ID: 17988123
if the error is in this line: result = (int)dbCommand.ExecuteScalar();

then make a break point in it and verify what value is the stored returning
0
 

Author Comment

by:jung1975
ID: 17988793
it returns 0 , but I know the sp procudure should reture a value...
0
 
LVL 5

Assisted Solution

by:Collindsouza
Collindsouza earned 1000 total points
ID: 18003845
jung1975

when u run the sp on its own.. does it retrieve any values???
0

Featured Post

Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Today is the age of broadband.  More and more people are going this route determined to experience the web and it’s multitude of services as quickly and painlessly as possible. Coupled with the move to broadband, people are experiencing the web via …
International Data Corporation (IDC) prognosticates that before the current the year gets over disbursing on IT framework products to be sent in cloud environs will be $37.1B.
Do you want to know how to make a graph with Microsoft Access? First, create a query with the data for the chart. Then make a blank form and add a chart control. This video also shows how to change what data is displayed on the graph as well as form…
In this video, Percona Solutions Engineer Barrett Chambers discusses some of the basic syntax differences between MySQL and MongoDB. To learn more check out our webinar on MongoDB administration for MySQL DBA: https://www.percona.com/resources/we…
Suggested Courses
Course of the Month12 days, 17 hours left to enroll

777 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question