1. This site uses cookies. By continuing to use this site, you are agreeing to our use of cookies. Learn More.

help me to draw table in C# windows form application

Discussion in 'C#' started by prasadvarma, Apr 15, 2014.

  1. prasadvarma

    prasadvarma New Member

    Joined:
    Apr 15, 2014
    Messages:
    1
    Likes Received:
    0
    Trophy Points:
    0
    Location:
    chennai
    Home Page:
    Can anyone tell me how to display the table in windows form application? shall i use datagrid view? and i need to display 6 rows and n number of columns according to the user input
     
  2. sangethvarmas

    sangethvarmas New Member

    Joined:
    Apr 29, 2014
    Messages:
    1
    Likes Received:
    0
    Trophy Points:
    0
    Location:
    chennai
    Home Page:
    You can refer online sources, there are lot of website having details about creating table in windows form.
     
  3. Ami Desai

    Ami Desai Member

    Joined:
    Jan 5, 2017
    Messages:
    42
    Likes Received:
    17
    Trophy Points:
    8
    Location:
    Ahmedabad
    Home Page:
    Hi,

    You can check this

    Code:
    using System.Data;
    using System.Data.SqlClient;
    public partial class Form1 : Form
    {
    public Form1()
      {
      InitializeComponent();
      BindGrid();
      }
    
    private void BindGrid()
      {
    string constring = @"Data Source=.\SQL2005;Initial Catalog=Northwind;User id = sa;password=pass@123";
    using (SqlConnection con = new SqlConnection(constring))
      {
    using (SqlCommand cmd = new SqlCommand("SELECT * FROM Customers", con))
      {
       cmd.CommandType = CommandType.Text;
    using (SqlDataAdapter sda = new SqlDataAdapter(cmd))
      {
    using (DataTable dt = new DataTable())
      {
      sda.Fill(dt);
       dataGridView1.DataSource = dt;
      }
      }
      }
      }
      }
    }
    Thanks
     

Share This Page