0

Hello Frends I am getting an error. The details are follows,

ERROR:

Exception Details: System.FormatException: Input string was not in a correct format.

Source Error:

Line 36:             if (rdr.Read())
Line 37:             {
[COLOR="Red"][B]Line 38:                 matured_month = Convert.ToInt32(rdr.GetString(0));[/B][/COLOR]
Line 39:                 matured_year = Convert.ToInt32(rdr.GetString(1));
Line 40:                 conn.Close();

CODE:

protected void Page_Load(object sender, EventArgs e)
    {
        int cu_month = Convert.ToInt32(DateTime.Now.Month.ToString());
        int cu_year=Convert.ToInt32(DateTime.Now.Year.ToString());
        int matured_month=0;        
        int matured_year=0;
        SqlConnection conn = new SqlConnection(ConfigurationManager.AppSettings["ConnectionString"]);
        conn.Open();
        DataSet ds = new DataSet();
        SqlDataAdapter adapter = new SqlDataAdapter("SELECT * FROM customer_details where adjustable_date like '%/%'", conn);
        adapter.Fill(ds);
        GridView1.DataSource = ds.Tables[0];
        GridView1.DataBind();
        conn.Close();
        foreach (GridViewRow row in GridView1.Rows)
        {
            conn.Open();
            SqlCommand cmd = new SqlCommand("select substring(adjustable_date,4,2),substring(adjustable_date,7,4) from customer_details where customer_id='" + GridView1.DataKeys[row.RowIndex].Value.ToString() + "' ", conn);
            SqlDataReader rdr = cmd.ExecuteReader();
            if (rdr.Read())
            {
                [COLOR="Red"]matured_month = Convert.ToInt32(rdr.GetString(0));[/COLOR]
                matured_year = Convert.ToInt32(rdr.GetString(1));
                conn.Close();
            }
            if (cu_month == matured_month && cu_year == matured_year)
            {
                CheckBox checkbox = (CheckBox)row.FindControl("chkRows");
                checkbox.Checked = true;
                row.BackColor = System.Drawing.Color.Yellow;
            }
            if (cu_month + 1 == matured_month && cu_year == matured_year)
            {
                CheckBox checkbox = (CheckBox)row.FindControl("chkRows");
                checkbox.Checked = true;
                row.BackColor = System.Drawing.Color.YellowGreen;
            }

        }

Please tell me what I am doing wrong here. Why I am not getting any value in the line 38.

Edited by mike_2000_17: Fixed formatting

2
Contributors
2
Replies
3
Views
6 Years
Discussion Span
Last Post by Sinha's
0

Hello Frends I am getting an error. The details are follows,
--------------------------------------------------------
ERROR:

Exception Details: System.FormatException: Input string was not in a correct format.

Source Error:

Line 36: if (rdr.Read())
Line 37: {
Line 38: matured_month = Convert.ToInt32(rdr.GetString(0));
Line 39: matured_year = Convert.ToInt32(rdr.GetString(1));
Line 40: conn.Close();

---------------------------------------------------------

CODE:

protected void Page_Load(object sender, EventArgs e)
{
int cu_month = Convert.ToInt32(DateTime.Now.Month.ToString());
int cu_year=Convert.ToInt32(DateTime.Now.Year.ToString());
int matured_month=0;
int matured_year=0;
SqlConnection conn = new SqlConnection(ConfigurationManager.AppSettings["ConnectionString"]);
conn.Open();
DataSet ds = new DataSet();
SqlDataAdapter adapter = new SqlDataAdapter("SELECT * FROM customer_details where adjustable_date like '%/%'", conn);
adapter.Fill(ds);
GridView1.DataSource = ds.Tables[0];
GridView1.DataBind();
conn.Close();
foreach (GridViewRow row in GridView1.Rows)
{
conn.Open();
SqlCommand cmd = new SqlCommand("select substring(adjustable_date,4,2),substring(adjustable_date,7,4) from customer_details where customer_id='" + GridView1.DataKeys[row.RowIndex].Value.ToString() + "' ", conn);
SqlDataReader rdr = cmd.ExecuteReader();
if (rdr.Read())
{
matured_month = Convert.ToInt32(rdr.GetString(0));
matured_year = Convert.ToInt32(rdr.GetString(1));
conn.Close();
}
if (cu_month == matured_month && cu_year == matured_year)
{
CheckBox checkbox = (CheckBox)row.FindControl("chkRows");
checkbox.Checked = true;
row.BackColor = System.Drawing.Color.Yellow;
}
if (cu_month + 1 == matured_month && cu_year == matured_year)
{
CheckBox checkbox = (CheckBox)row.FindControl("chkRows");
checkbox.Checked = true;
row.BackColor = System.Drawing.Color.YellowGreen;
}

}

Please tell me what I am doing wrong here. Why I am not getting any value in the line 38.

Hi


Pls. try something like this

Private Sub LoadData()
Dim dr As SqlDataReader
dr = db.ExecuteReader(SpName, Params)
        If dr.HasRows = True Then
            While dr.Read
              'do something...
            End While
            Return items.ToArray
        End If
end if

you can covert this code to C#

Mark as solved if it helps you!!!

0

Nopes!! Not solved. Is my query is correct-

("select substring(adjustable_date,4,2),substring(adjustable_date,7,4) from customer_details where customer_id='" + GridView1.DataKeys[row.RowIndex].Value.ToString() + "' ", conn);

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.