Solved

executing Stored procedure and error

Posted on 2006-11-21
3
220 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
3 Comments
 
LVL 17

Accepted Solution

by:
lem2802 earned 250 total points
Comment Utility
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
Comment Utility
it returns 0 , but I know the sp procudure should reture a value...
0
 
LVL 5

Assisted Solution

by:Collindsouza
Collindsouza earned 250 total points
Comment Utility
jung1975

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

Featured Post

Do You Know the 4 Main Threat Actor Types?

Do you know the main threat actor types? Most attackers fall into one of four categories, each with their own favored tactics, techniques, and procedures.

Join & Write a Comment

Suggested Solutions

Problem Hi all,    While many today have fast Internet connection, there are many still who do not, or are connecting through devices with a slower connect, so light web pages and fast load times are still popular.    If your ASP.NET page …
It was really hard time for me to get the understanding of Delegates in C#. I went through many websites and articles but I found them very clumsy. After going through those sites, I noted down the points in a easy way so here I am sharing that unde…
Illustrator's Shape Builder tool will let you combine shapes visually and interactively. This video shows the Mac version, but the tool works the same way in Windows. To follow along with this video, you can draw your own shapes or download the file…
Polish reports in Access so they look terrific. Take yourself to another level. Equations, Back Color, Alternate Back Color. Write easy VBA Code. Tighten space to use less pages. Launch report from a menu, considering criteria only when it is filled…

763 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

Need Help in Real-Time?

Connect with top rated Experts

10 Experts available now in Live!

Get 1:1 Help Now