Solved

executing Stored procedure and error

Posted on 2006-11-21
3
229 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 250 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 250 total points
ID: 18003845
jung1975

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

Featured Post

Industry Leaders: 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

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…
In .NET 2.0, Microsoft introduced the Web Site.  This was the default way to create a web Project in Visual Studio 2005.  In Visual Studio 2008, the Web Application has been restored as the default web Project in Visual Studio/.NET 3.x The Web Si…
Come and listen to Percona CEO Peter Zaitsev discuss what’s new in Percona open source software, including Percona Server for MySQL (https://www.percona.com/software/mysql-database/percona-server) and MongoDB (https://www.percona.com/software/mongo-…
Michael from AdRem Software outlines event notifications and Automatic Corrective Actions in network monitoring. Automatic Corrective Actions are scripts, which can automatically run upon discovery of a certain undesirable condition in your network.…

688 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