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:
    http://www.soundtechmedia.com/audio_technology.html
    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:
    http://www.webdesigninchennai.in/seo-digital-marketing.html
    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:
    http://www.ifourtechnolab.com/
    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

  1. This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
    By continuing to use this site, you are consenting to our use of cookies.
    Dismiss Notice