Click here to Skip to main content
15,891,375 members
Please Sign up or sign in to vote.
1.33/5 (2 votes)
See more:
i have developed a code using select statement.
but it doesn't give me a output even
just blank gridview?

C#
string connectionString = "Data Source=C:\\Users\\Jeewani\\Documents\\rundown.sdf;";

            SqlCeConnection sql = new SqlCeConnection(connectionString);

            sql.Open();

            string query = "select * from ItemsNames";


            SqlCeCommand myCommand = new SqlCeCommand(query, sql);

            SqlCeDataReader reader = myCommand.ExecuteReader();

            Viewer.DataSource = reader;
            //name of the datagridview is viewer      

        
            sql.Close();
Posted
Updated 10-May-15 17:51pm
v2
Comments
[no name] 11-May-15 1:17am    
http://chalaki.com/using-ado-net-sqlcecommand-sqlcedatareader-to-select-data-from-sql-server-compact/204/

1 solution

Use SqlCeDataAdapter instead of SqlCeDataReader and Change the code like this way

SqlCeDataAdapter sqlceda = new SqlCeDataAdapter(myCommand);
           
           DataSet dsData = new DataSet("ITEMNAMES");
           sqlceda.Fill(dsData);
           Viewer.DataSource = ds.Tables[0];

thanks
 
Share this answer
 
v2

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900