Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7399041
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 29, 20262026-05-29T04:00:24+00:00 2026-05-29T04:00:24+00:00

I am developing a WinFrom application. I am using SDF database to store data.

  • 0

I am developing a WinFrom application. I am using SDF database to store data.
The below code snippet to load the data to datagrid from DataBase is hanging the application. When I am clicking on the datagrid,
“Invalid attempt to call method Updatable when SqlResultSet is closed” exception is being thrown.

public partial class Form1 : Form
{
   private SqlCeConnection _conn;

   public Form1()
   {
       InitializeComponent();
       _conn = new SqlCeConnection(@"Data Source = |DataDirectory|\Database1.sdf");
       this.dataGridView1.AutoGenerateColumns = true;
   }

   private void Form1_Load(object sender, EventArgs e)
   {
       SqlCeCommand sqlcmd = new SqlCeCommand();
       sqlcmd.Connection = _conn;
       sqlcmd.CommandText = "SELECT ID, UserName FROM Table1";
       _conn.Open();

       SqlCeResultSet rs = sqlcmd.ExecuteResultSet(ResultSetOptions.Scrollable);
       this.bindingSource1.DataSource = rs;
       _conn.Close();

   }
}

Can anybody please look into it?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-29T04:00:25+00:00Added an answer on May 29, 2026 at 4:00 am

    Try this

    public partial class Form1 : Form
    {
       private SqlCeConnection _conn;
    
       public Form1()
       {
         InitializeComponent();
         this.dataGridView1.AutoGenerateColumns = true;
       }
    
       private void Form1_Load(object sender, EventArgs e)
       {
         SqlCeDataReader rdr = null;
         try
         {
           using(SqlCeConnection conn = new SqlCeConnection(@"Data Source = |DataDirectory|\Database1.sdf"))
           {
               conn.Open();
    
               SqlCeCommand sqlcmd = new SqlCeCommand("SELECT ID, UserName FROM Table1", conn);
               sqlcmd.Connection.Open();
    
               rdr = sqlcmd.ExecuteReader();
    
               //Custom Object is object with same structure as your data table
               List<CustomObject> dataSource = new List<CustomObject>();
               while (rdr.Read())
               {
                   var customObject = new CustomObject();
                   customObject.Id = rdr.GetInt32(0);
                   //so on
    
                   dataSource.Add(customObject);
               }
    
               this.bindingSource1.DataSource = dataSource;
               rdr.Close();
           }
        }
        catch(Exception ex)
        { 
           //Handle Exception
        }
      }
    }
    

    You can check this post too. You will need to keep connection open for binding dataset directly. Instead of doing that map it to some local object and bind that.

    Hope this works for you.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Developing a Sencha Touch MVC app that pulls data from json store (thats set
I am using C# and developing a winform application. I have a project class
I'm developing an winform application for Windows Mobile 5.0 and above. I'm using .Net
Hi I'm developing a winform application using C# and the entity framework (linq to
I'm developing a winform application. I want to take input from user (i.e. the
I am developing a small business application which uses Sqlserver 2005 database. Platform: .Net
I am developing an winform application in .NET framework 3.5, using C#. In the
Background: I'm developing a WinForms application using C# with an OpenFileDialog and FileBrowserDialog that
I am developing a WinForm application using VB.NET (I am fluent in C# as
I'm developing a Windows Mobile 5.0 or above WinForm application using .NET Compact Framework

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.