Click here to Skip to main content
15,891,981 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
I am working on a GUI form and i put one button named display on form.I want that when i click on that button then the data grid view will appear on the screen which contained that forms data which is linked with database through binding source.
Posted

1 solution

check this on button keypress event

C#
if(e.Keychar == (char)13)
{
    string strSQLconnection = "Data Source=dbServer;Initial Catalog=testDB;Integrated Security=True";
    SqlConnection sqlConnection = new SqlConnection(strSQLconnection);
    SqlCommand sqlCommand = new SqlCommand("SELECT * FROM TABLENAME", sqlConnection);
    sqlConnection.Open();
 
    SqlDataReader reader = sqlCommand.ExecuteReader();
       
    GridView1.DataSource = reader;
    GridView1.DataBind();
    GridView1.Visible = true;
    GridView1.Focus();
}


hope this will help you

Also check this link for reference

How to populate DataGridView, GridView with SQL statement in C#[^]
 
Share this answer
 
v2
Comments
Sergey Alexandrovich Kryukov 26-Feb-12 2:01am    
Voted 1 just for checking keychar with 13 -- very bad.
--SA
Aniket Yadav 27-Feb-12 0:12am    
Thanks --SA
Am i missing any other thing... If yes then please let me know... It will be highly appreciated.

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