Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
?
Solved

executing Stored procedure and error

Posted on 2006-11-21
3
Medium Priority
?
244 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

Concerto Cloud for Software Providers & ISVs

Can Concerto Cloud Services help you focus on evolving your application offerings, while delivering the best cloud experience to your customers? From DevOps to revenue models and customer support, the answer is yes!

Learn how Concerto can help you.

Question has a verified solution.

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

I have developed many web applications with asp & asp.net and to add and use a dropdownlist was always a very simple task, but with the new asp.net, setting the value is a bit tricky and its not similar to the old traditional method. So in this a…
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.
In this video you will find out how to export Office 365 mailboxes using the built in eDiscovery tool. Bear in mind that although this method might be useful in some cases, using PST files as Office 365 backup is troublesome in a long run (more on t…
Sometimes it takes a new vantage point, apart from our everyday security practices, to truly see our Active Directory (AD) vulnerabilities. We get used to implementing the same techniques and checking the same areas for a breach. This pattern can re…

597 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