//This connection string is used to connect to database
String strConnection = "Data Source=MYSYSTEM;Initial Catalog=MySamplesDB;Integrated Security=True";
//Establish SQL Connection
SqlConnection con = new SqlConnection(strConnection);
//Open database connection to connect to SQL Server
//Data table is used to bind the resultant data
DataTable dtusers = new DataTable();
// Create a new data adapter based on the specified query.
SqlDataAdapter da = new SqlDataAdapter("Select * from User_Information", con);
//SQl command builder is used to get data from database based on query
SqlCommandBuilder cmd = new SqlCommandBuilder(da);
//Fill data table
//assigning data table to Datagridview
dataGridView1.DataSource = dtusers;
//Resize the Datagridview column to fit the gridview columns with data in datagridview
By: Suresh Dasari Dec 27, 2010
Here I will explain how to bind Datagridview in windows application using c#.net.
I have started working on windows application at that time I don’t know how to use Datagridview and other controls. I face some problems to bind data to Datagridview and to other controls that’s why I am writing this post to explain how to bind data to Datagridview in windows application. In windows application binding Datagridview is somewhat different when compared with web application Datagridview binding.
First create one windows forms application now form.cs will open after that drag and drop Datagridview from All windows form category after that write the following code in code behind to bind data to Datagridview.
After bind data to datagridview that should be like this
Other Related Posts
- Interview Questions in ASP.NET,C#.NET,SQL Server,.NET Framework
- Asp.net insert, Edit, update, delete data in gridview
- 3 tier architecture example in asp.net with C#
- Introduction to Object Oriented Programming Concepts (OOPS) in C#.net
- Simple login form example in asp.net Check Username and Password availability in database
- Introduction to WCF - WCF tutorial | WCF Tutorial - Windows Communication Foundation | WCF Example | WCF Sample code in asp.net 3.5 | Basic WCF Tutorial for Beginners
- how to insert images into database and how to retrieve and bind images to gridview using asp.net (or) save and retrieve images from database using asp.net
- jQuery 360 Degrees Image Display Plugins Examples with Tutorial
- Asp.net WebService or Creating and Consuming WebService in asp.net or Create and call webservice in asp.net or how to create webservice and how to use webservice in asp.net
- Best Login Page Design in HTML, CSS with Source Code