Hi some time i getting error below ,but i am did't used excutereader
ExecuteReader requires an open and available Connection. The connection's current state is closed.
this my code,
try
{
if (con.State != ConnectionState.Open)
con.Open();
string result;
string Queryip = "ViewIp";
SqlCommand cmdip = new SqlCommand("ViewTranscation", con);
cmdip.CommandType = CommandType.StoredProcedure;
cmdip.Parameters.AddWithValue("@QueryType", Queryip);
cmdip.Parameters.AddWithValue("@Input1", "");
SqlDataAdapter adip = new SqlDataAdapter(cmdip);
DataSet dsip = new DataSet();
adip.Fill(dsip);
if (dsip.Tables[0].Rows.Count != 0)
{
for (int a = 0; a < dsip.Tables[0].Rows.Count; a++)
{
short ContID = Convert.ToInt16(dsip.Tables[0].Rows[a]["IPId"].ToString());
string IP = dsip.Tables[0].Rows[a]["IPAddress"].ToString();
string rdata = "";
short SlaveID = Convert.ToInt16(dsip.Tables[0].Rows[a]["SlaveId"].ToString());
short PortNum = 1234;
short Contresult = objSmart.GetControllerInfo(ContID, ref rdata);
string res1 = Contresult.ToString();
if (res1 != "0")
{
result = objSmart.AddController(ref ContID, ref IP, ref PortNum, ref SlaveID).ToString();
if (result == "0")
{
short cnt = 1, b = 0, trcnt = 100;
string rOut = "";
short wer = objSmart.GetMultiTransaction(cnt, trcnt, ref rOut, b);
string input = rOut;
string[] values = input.Split(new char[] { ',' }, StringSplitOptions.RemoveEmptyEntries);
List<string> list = values.ToList<string>();
int j = 1;
for (int i = 0; i < values.Length - 2; i++)
{
String newValue = values[i];
list.Add(newValue);
if (j % 10 == 0)
{
string Chn = list[0].ToString();
string Evn = list[1].ToString();
string Pass = list[2].ToString();
string hh = list[3].ToString();
string dd = list[4].ToString();
string Notr = list[5].ToString();
string readerpt = list[6].ToString();
string Accty = list[7].ToString();
string chksum = list[8].ToString();
string Notrns = list[9].ToString();
char[] arraytime = hh.ToCharArray();
string hours1 = arraytime[0].ToString();
string hours2 = arraytime[1].ToString();
string min1 = arraytime[2].ToString();
string min2 = arraytime[3].ToString();
string sec1 = arraytime[4].ToString();
string sec2 = arraytime[5].ToString();
String Totalhr = hours1 + "" + hours2 + ":" + min1 + "" + min2 + ":" + sec1 + "" + sec2;
char[] arraydate = dd.ToCharArray();
string d0 = arraydate[0].ToString();
string d1 = arraydate[1].ToString();
string d2 = arraydate[2].ToString();
string d3 = arraydate[3].ToString();
string d4 = arraydate[4].ToString();
string d5 = arraydate[5].ToString();
string Yprfix = "20";
//String fullDate = d0 + "" + d1 + "/" + d2 + "" + d3 + "/" + Yprfix + "" + d4 + "" + d5;
string fullDate = Yprfix + "" + d4 + "" + d5 + "/" + d2 + "" + d3 + "/" + d0 + "" + d1;
string Datetime = fullDate + " " + Totalhr; con1.Open();
SqlCommand cmdchkpass = new SqlCommand("select BarcodeId from mstr_workforce where BarcodeId=" + Pass + " and WFStatus='Y'", con1);
SqlDataAdapter ad = new SqlDataAdapter(cmdchkpass); con1.Close();
DataSet ds = new DataSet(); ad.Fill(ds);
if (ds.Tables[0].Rows.Count != 0)
{
con2.Open();
SqlCommand cmdtrns = new SqlCommand("insert into WorkforceAtten(WorkforceID,AttendanceDate,CreateDate) values ((select WorkforceId from mstr_workforce where BarcodeId='" + Pass + "' ),'" + fullDate + "','" + Datetime + "') ", con2);
int res = cmdtrns.ExecuteNonQuery(); con2.Close();
if (res > 0)
{
list.Clear();
}
list.Clear();
}
else
{ list.Clear(); }
}
j++;
}
short delete = objSmart.DeleteMultiTransaction(cnt, trcnt, ref rOut, b);
}
}
}
adip.Dispose();
}
}
catch (Exception ex)
{ }
if (con.State == ConnectionState.Open)
con.Close();
please provide solution