Click here to Skip to main content
15,881,938 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
i want to bind the local database to datagridview local database does not need the sql database so how to do this i don't knw..
I use this code bt it cant work..

C#
string rr = @"Data Source=F:\Works\WindowsApp\clob\clob\Database12.sdf";
           using (con = new SqlConnection(rr))
           {
               cmd = new SqlCommand(@"SELECT uId, pass FROM users", con);
               //cmd.CommandType = System.Data.CommandType.StoredProcedure;
               //cmd.Parameters.AddWithValue("@date", datePicker.Value);
               //cmd.Parameters.AddWithValue("@roomNumber", cmboRoom.Text);
               con.Open();
               using (SqlDataAdapter sda = new SqlDataAdapter(cmd))
               {
                   using (DataTable dt = new DataTable())
                   {
                       sda.Fill(dt);
                       dataGridView1.DataSource = dt;
                   }
               }
Posted

1 solution

If you are looking for the disconnected approach to populate a grid view, please try -
Querying a Database: Disconnected Approach[^]
How to bind DataGridView with Connected and Dis Connected Mode in Ado.Net[^]
 
Share this answer
 

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