Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. C#
  4. get data in datagridview

get data in datagridview

Scheduled Pinned Locked Moved C#
csharpquestioncssdatabasedesign
10 Posts 3 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • N Offline
    N Offline
    Nekshan
    wrote on last edited by
    #1

    i m making an application in c#.net2005, window application. How can i connect datagridview to database(sqlserver2000) at runtime? - not from design, only by coding. i have written this code, but no data is listed in grid : SqlConnection conn = new SqlConnection("Data Source=......"); private void Form1_Load(object sender, EventArgs e) { conn.Open(); SqlDataAdapter da = new SqlDataAdapter("select * from tblsummary", conn); DataSet ds = new DataSet(); da.Fill(ds, "tblsummary"); //dataGridView1.Columns.Add(sitehit); dataGridView1.DataSource = ds; conn.Close(); } Does i miss something else for connection? Hope to get a reply.. thank you in adv. nekshan.

    V K 4 Replies Last reply
    0
    • N Nekshan

      i m making an application in c#.net2005, window application. How can i connect datagridview to database(sqlserver2000) at runtime? - not from design, only by coding. i have written this code, but no data is listed in grid : SqlConnection conn = new SqlConnection("Data Source=......"); private void Form1_Load(object sender, EventArgs e) { conn.Open(); SqlDataAdapter da = new SqlDataAdapter("select * from tblsummary", conn); DataSet ds = new DataSet(); da.Fill(ds, "tblsummary"); //dataGridView1.Columns.Add(sitehit); dataGridView1.DataSource = ds; conn.Close(); } Does i miss something else for connection? Hope to get a reply.. thank you in adv. nekshan.

      V Offline
      V Offline
      virendra patel
      wrote on last edited by
      #2

      private void Form1_Load(object sender, EventArgs e) { ' Create Instance of Connection and Command Object Dim myConnection As SqlConnection = New SqlConnection(System.Configuration.ConfigurationManager.AppSettings("ConnectionString")) Dim myCommand As SqlCommand = New SqlCommand("select statement", myConnection) ' Execute the command myConnection.Open() Dim result As SqlDataReader = myCommand.ExecuteReader(CommandBehavior.CloseConnection) DataSet ds = new DataSet(); da.Fill(ds); dataGridView1.DataSource = ds.tables(0); } convert this in c# some code is paste from vb.net that's y. open www.meebo.com to chat with me this site give facility to chat by using yahoo login ok.

      V N 3 Replies Last reply
      0
      • V virendra patel

        private void Form1_Load(object sender, EventArgs e) { ' Create Instance of Connection and Command Object Dim myConnection As SqlConnection = New SqlConnection(System.Configuration.ConfigurationManager.AppSettings("ConnectionString")) Dim myCommand As SqlCommand = New SqlCommand("select statement", myConnection) ' Execute the command myConnection.Open() Dim result As SqlDataReader = myCommand.ExecuteReader(CommandBehavior.CloseConnection) DataSet ds = new DataSet(); da.Fill(ds); dataGridView1.DataSource = ds.tables(0); } convert this in c# some code is paste from vb.net that's y. open www.meebo.com to chat with me this site give facility to chat by using yahoo login ok.

        V Offline
        V Offline
        virendra patel
        wrote on last edited by
        #3

        Dim myConnection As SqlConnection = New SqlConnection(write u'r connecting string over here) in prev code.

        1 Reply Last reply
        0
        • N Nekshan

          i m making an application in c#.net2005, window application. How can i connect datagridview to database(sqlserver2000) at runtime? - not from design, only by coding. i have written this code, but no data is listed in grid : SqlConnection conn = new SqlConnection("Data Source=......"); private void Form1_Load(object sender, EventArgs e) { conn.Open(); SqlDataAdapter da = new SqlDataAdapter("select * from tblsummary", conn); DataSet ds = new DataSet(); da.Fill(ds, "tblsummary"); //dataGridView1.Columns.Add(sitehit); dataGridView1.DataSource = ds; conn.Close(); } Does i miss something else for connection? Hope to get a reply.. thank you in adv. nekshan.

          V Offline
          V Offline
          virendra patel
          wrote on last edited by
          #4

          private void Form1_Load(object sender, EventArgs e) { Dim connectionString As String = "server='(local)'; trusted_connection=true; database='webstore'" Dim dbConnection As System.Data.IDbConnection = New System.Data.SqlClient.SqlConnection("Data Source=write connecting string over here") Dim queryString As String = "SELECT [Categories].[CategoryID], [Categories].[CategoryText] FROM [Categories]" Dim dbCommand As System.Data.IDbCommand = New System.Data.SqlClient.SqlCommand dbCommand.CommandText = queryString dbCommand.Connection = dbConnection Dim dataAdapter As System.Data.IDbDataAdapter = New System.Data.SqlClient.SqlDataAdapter dataAdapter.SelectCommand = dbCommand Dim dataSet As System.Data.DataSet = New System.Data.DataSet dataAdapter.Fill(dataSet) dataGridView1.DataSource = ds.tables(0); conn.Close(); }

          1 Reply Last reply
          0
          • V virendra patel

            private void Form1_Load(object sender, EventArgs e) { ' Create Instance of Connection and Command Object Dim myConnection As SqlConnection = New SqlConnection(System.Configuration.ConfigurationManager.AppSettings("ConnectionString")) Dim myCommand As SqlCommand = New SqlCommand("select statement", myConnection) ' Execute the command myConnection.Open() Dim result As SqlDataReader = myCommand.ExecuteReader(CommandBehavior.CloseConnection) DataSet ds = new DataSet(); da.Fill(ds); dataGridView1.DataSource = ds.tables(0); } convert this in c# some code is paste from vb.net that's y. open www.meebo.com to chat with me this site give facility to chat by using yahoo login ok.

            N Offline
            N Offline
            Nekshan
            wrote on last edited by
            #5

            da.Fill(ds); what is 'da' in your code? no definition for it. nekshan.

            1 Reply Last reply
            0
            • V virendra patel

              private void Form1_Load(object sender, EventArgs e) { ' Create Instance of Connection and Command Object Dim myConnection As SqlConnection = New SqlConnection(System.Configuration.ConfigurationManager.AppSettings("ConnectionString")) Dim myCommand As SqlCommand = New SqlCommand("select statement", myConnection) ' Execute the command myConnection.Open() Dim result As SqlDataReader = myCommand.ExecuteReader(CommandBehavior.CloseConnection) DataSet ds = new DataSet(); da.Fill(ds); dataGridView1.DataSource = ds.tables(0); } convert this in c# some code is paste from vb.net that's y. open www.meebo.com to chat with me this site give facility to chat by using yahoo login ok.

              N Offline
              N Offline
              Nekshan
              wrote on last edited by
              #6

              thanx its working. www.meebo.com is not allowed :-( i'll try again. how r u? wen r u coming?? c u soon!! nekshan.

              V 1 Reply Last reply
              0
              • N Nekshan

                thanx its working. www.meebo.com is not allowed :-( i'll try again. how r u? wen r u coming?? c u soon!! nekshan.

                V Offline
                V Offline
                virendra patel
                wrote on last edited by
                #7

                use this & check. http://wwwl.meebo.com/index-en-GB.html fine.i m coming on 1st may.after 1 week.

                1 Reply Last reply
                0
                • N Nekshan

                  i m making an application in c#.net2005, window application. How can i connect datagridview to database(sqlserver2000) at runtime? - not from design, only by coding. i have written this code, but no data is listed in grid : SqlConnection conn = new SqlConnection("Data Source=......"); private void Form1_Load(object sender, EventArgs e) { conn.Open(); SqlDataAdapter da = new SqlDataAdapter("select * from tblsummary", conn); DataSet ds = new DataSet(); da.Fill(ds, "tblsummary"); //dataGridView1.Columns.Add(sitehit); dataGridView1.DataSource = ds; conn.Close(); } Does i miss something else for connection? Hope to get a reply.. thank you in adv. nekshan.

                  K Offline
                  K Offline
                  Keshav V Kamat 0
                  wrote on last edited by
                  #8

                  just an alternate method by using the data reader

                  SqlConnection conn = new SqlConnection("Data Source=" + Environment.MachineName + "\\WINCC;Integrated Security=SSPI;Initial Catalog=Logger; Packet Size = 32766;");
                  SqlCommand cmd = new SqlCommand("SELECT * FROM RDPLogViewer WHERE SubSystem = '" + SubSystemComboBox.Text + "'", conn);
                  SqlDataReader rdr = cmd.ExecuteReader();
                  while (rdr.Read())
                  {
                  LoggerDatagrid.Rows.Add(rdr["TypeLevel"].ToString(), rdr["TimeStamp"].ToString(), rdr["SubSystem"].ToString(), rdr["ClassName"].ToString(), rdr["FunctionUsed"].ToString(), rdr["Memory"].ToString(), rdr["Statement"].ToString());
                  }

                  Assuming that the variables are existing in the respective tables/database

                  Keshav Kamat :) India

                  1 Reply Last reply
                  0
                  • N Nekshan

                    i m making an application in c#.net2005, window application. How can i connect datagridview to database(sqlserver2000) at runtime? - not from design, only by coding. i have written this code, but no data is listed in grid : SqlConnection conn = new SqlConnection("Data Source=......"); private void Form1_Load(object sender, EventArgs e) { conn.Open(); SqlDataAdapter da = new SqlDataAdapter("select * from tblsummary", conn); DataSet ds = new DataSet(); da.Fill(ds, "tblsummary"); //dataGridView1.Columns.Add(sitehit); dataGridView1.DataSource = ds; conn.Close(); } Does i miss something else for connection? Hope to get a reply.. thank you in adv. nekshan.

                    K Offline
                    K Offline
                    Keshav V Kamat 0
                    wrote on last edited by
                    #9

                    You can also use a dataset/data table to bind the database table contents to the datagrid.

                    Keshav Kamat :) India

                    N 1 Reply Last reply
                    0
                    • K Keshav V Kamat 0

                      You can also use a dataset/data table to bind the database table contents to the datagrid.

                      Keshav Kamat :) India

                      N Offline
                      N Offline
                      Nekshan
                      wrote on last edited by
                      #10

                      Thank you Sir, yes it is working now :-) Regards Nekshan.

                      1 Reply Last reply
                      0
                      Reply
                      • Reply as topic
                      Log in to reply
                      • Oldest to Newest
                      • Newest to Oldest
                      • Most Votes


                      • Login

                      • Don't have an account? Register

                      • Login or register to search.
                      • First post
                        Last post
                      0
                      • Categories
                      • Recent
                      • Tags
                      • Popular
                      • World
                      • Users
                      • Groups