1
Answer

Error.Conversion failed when converting the varchar value 'April' to data type int. C# .net

dhanu sahu

dhanu sahu

16y
9.1k
1
Hi Friends,My problem till Same Unsolved(months,year is varchar)I want to  filter my data according to month and year in supply


protected void BtnSubmit_Click(object sender, EventArgs e)
   {
       int TotTime = Convert.ToInt32(Endtime.SelectedValue) - Convert.ToInt32(Sttime.SelectedValue);
       SqlCommand sqlcmd = new SqlCommand("insert into D_TimeSheet1(EmpId,attDate,AttIn,AttOut,AttDay,TotalTime,Remarks,CreatedOn,Task,Months,Day,Year) VALUES ('" + Session["usid"].ToString() + "','" + lbldate.Text + "','" + Sttime.SelectedItem.Text + "','" + Endtime.SelectedItem.Text + "','" + lblday.Text + "','" + TotTime + "','" + txtremark.Text + "','" + DateTime.Now.ToString() + "','" + TextBox1.Text + "','" + Label2.Text + "','" + Label1.Text + "','" + Label3.Text + "')", new SqlConnection(strcon));
       sqlcmd.Connection.Open();
       sqlcmd.ExecuteNonQuery();
       sqlcmd.Connection.Close();
       Bindgrid();

   }
   public void Bindgrid()
   {
       string strsql="select * from D_TimeSheet1 where EmpId="+Session ["usid"]+" AND Months="+date .Month +" AND Year="+date .Year +" order By AttDate DESC";
       string strcount = "select count(*) from D_TimeSheet1 where EmpId=" + Session["usid"] + " AND Months=" + Convert .ToInt32 ( date.Month )+ " AND year=" + date.Year + "";
       SqlCommand cmd = new SqlCommand(strsql, new SqlConnection(strcon));
       SqlCommand cmdcount = new SqlCommand(strcount, new SqlConnection(strcon));
       cmd.Connection.Open();
       cmdcount.Connection.Open();

...................................................................................................................................
       int rownos =Convert.ToInt32 ( cmdcount.ExecuteScalar().ToString ());
....................................................................................................................................
       if (rownos > 0)
       {
           GVTime.DataSource = cmd.ExecuteReader();
           GVTime.DataBind();

       }
       cmd.Connection.Close();
       cmdcount.Connection.Close();
       
       string strcount1 = "select count(*) from D_TimeSheet1 where EmpId=" + Session["usid"] + " AND Months=" + date.Month + " AND year=" + date.Year + "";
       SqlCommand cmdcount1 = new SqlCommand(strcount1, new SqlConnection(strcon));
       cmdcount1.Connection.Open();
       int rownos1 =Convert .ToInt32 ( cmdcount1.ExecuteScalar());
       if (rownos1 > 0)
       {
           BtnSubmit.Enabled = false;
       }
   }
Answers (1)