give me this type error again and again:
Additional information: The connection was not closed. The connection's current state is open.
in the following code.
public void store_detailinsertion()
{
try
{
ConnectionString.cnn.Open();
cmd.Parameters.Clear();
cmd = new SqlCommand("Insert into store_detail (prdid,quantity,itemtotal) Values (@prdid,@quantity,@itemtotal)", ConnectionString.cnn);
cmd.Parameters.Add("@prdid", SqlDbType.VarChar).Value = mtbprdid.Text.ToString();
cmd.Parameters.Add("@quantity", SqlDbType.VarChar).Value = txtqty.Text.ToString();
cmd.Parameters.Add("@itemtotal", SqlDbType.VarChar).Value = txttotalstkqty.Text.ToString();
cmd.ExecuteNonQuery();
cmd.Connection.Close();
}
catch (Exception)
{
throw;
}
finally
{
ConnectionString.cnn.Close();
ConnectionString.cnn.Dispose();
}
}
public void store_detailUpdation()
{
try
{
ConnectionString.cnn.Open();
cmd.Connection = ConnectionString.cnn;
ConnectionString.cnn.Open();
cmd.CommandText = "Update store_detail set itemtotal='" + txttotalstkqty.Text + "',quantity='" + txtqty.Text + "' Where prdid='" + mtbprdid.Text + "'";
cmd.ExecuteNonQuery();
cmd.Connection.Close();
}
catch (Exception)
{
throw;
}
finally
{
ConnectionString.cnn.Close();
ConnectionString.cnn.Dispose();
}
}
private void store_detailOperation()
{
try
{
ConnectionString.cnn.Open();
DataSet ds = new DataSet();
SqlDataAdapter da = new SqlDataAdapter("select * from store_detail where prdid='" + mtbprdid.Text + "'", ConnectionString.cnn);
int s = (da.Fill(ds));
if (s >= 1)
{
store_detailUpdation();
}
else
{
store_detailinsertion();
}
}
catch (Exception)
{
throw;
}
finally
{
ConnectionString.cnn.Close();
ConnectionString.cnn.Dispose();
}
}
Plzzz, Anyone Can Help Me