0

Below code gives me output in datagridview it was previously working fine ande now it is giving me System.Stackoverflow error

enter image description here


static class SqlFunctions
{
    static private SqlCeConnection con = new SqlCeConnection(@"Data Source=|DataDirectory|\bazardb.sdf");

    static public void refresh(DataGridView datagrid)
    {
        try
        {
            if (con.State != ConnectionState.Open)
            {
                con.Open();
            }
            SqlCeDataAdapter dataadapter = new SqlCeDataAdapter("select * from item", con);
            DataTable datatable = new DataTable();
            dataadapter.Fill(datatable);
            datagrid.DataSource = datatable;

        }
        catch (SqlCeException e)
        {
            MessageBox.Show(e.ToString());
        }
        finally
        {
            con.Close();
        }
    }
Sherantha
  • 462
  • 3
  • 19
  • what did you change? – Sagar R May 05 '16 at 10:24
  • datagrid.BeginUpdate(); datagrid.DataSource = datat; datagrid.EndUpdate(); ?? – Sergey Petrov May 05 '16 at 10:30
  • 1
    debug the code. At what line does the exception throw? Can you post the full stack trace? – CathalMF May 05 '16 at 10:39
  • it shows error to dataadapter line – smart_coder May 05 '16 at 10:41
  • I'm guessing there is a loop here somewhere? and your refreshing it constantly? – Liam May 05 '16 at 10:55
  • nope only on form load i fill gridview or on update i refresh it – smart_coder May 05 '16 at 10:56
  • this is a Java question but the same applies here [What is a StackOverflowError?](http://stackoverflow.com/questions/214741/what-is-a-stackoverflowerror) – Liam May 05 '16 at 10:56
  • FYI this code is a memory leak waiting to happen, dispose of your objects. – Liam May 05 '16 at 10:57
  • @smart_coder How many results are you expecting to be returned by this query? Try and limit the results to see if it resolves to which will help troubleshoot. – CathalMF May 05 '16 at 10:58
  • @Liam it was previously showing error that connection is open,so i handled it by checking if connectionstate.isopen after that it is giving me this error ,i ll try to search if their is any recursive call – smart_coder May 05 '16 at 11:01
  • If you posted the stack trace as @CathalMF has suggested it'd make it much easier to identify the issue – Liam May 05 '16 at 11:03
  • @CathalMF i want results more than 1K may be coz i am showing item list, rightnow am testing with only 10-15 rows – smart_coder May 05 '16 at 11:03
  • @smart_coder You need to post the stack trace. Select the "View Detail" on the exception in visual studio and copy the stack trace value and post it to the question. – CathalMF May 05 '16 at 11:14
  • {Cannot evaluate expression because the current thread is in a stack overflow state.} -this details are shown when i clicked View Detail – smart_coder May 05 '16 at 11:26

0 Answers0