Click here to Skip to main content
15,894,955 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
how to bind the data in the gridview using the dataset
Posted

Start by picking up a beginners book on C#, just about everyone I've seen covers databinding.
 
Share this answer
 
Hers the code that will do the trick for u
C#
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using System.Data.SqlClient;
namespace WindowsApplication2
{
    public partial class Form1 : Form
    {
        public Form1()
        {
            InitializeComponent();
        }
        private void button1_Click(object sender, EventArgs e)
        {
            SqlConnection con = new SqlConnection();
            con.ConnectionString = "Data Source=.;Initial Catalog=master;Integrated Security=True";
            con.Open();
            SqlCommand cmd = new SqlCommand("select * from mytable", con);
            SqlDataAdapter adp = new SqlDataAdapter();
            DataSet ds = new DataSet();
            adp.Fill(ds);
            DataTable dt = ds.Tables[0];
            SqlDataReader dr = cmd.ExecuteReader();
            while (dr.Read() == true)
            {
                dataGridView1.DataSource = dt;
            }
            con.Close();
        }
    }
}


This is a C# code
Do Rate my answer once u find it useful

Thanks & Regards
Radix :rose:

[edit:rjm]If you must post an answer as code then please use the <pre></pre> tags.[/edit]
 
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