| | |
How to add rows from dataset to datagridview
Please support our C# advertiser: $4.95 a Month - ASP.NET Web Hosting – Click Here!
![]() |
•
•
Join Date: May 2006
Posts: 13
Reputation:
Solved Threads: 0
Hi all,
Please solve my Problem:
I have DataGridView and Dataset. I want to add data from dataset to datagridview row by row and not by using DataGridView.DataSource method.
For ex. following is the way to do the same using Vb.net
dgClient.Columns.Add("client", "Client")
dgClient.Columns("client").Width = 150
dgClient.Columns.Add("comments", "Comments")
dgClient.Columns("comments").Width = 250
Dim i As Integer
For i = 0 To dsClient.Tables("TableClient").Rows.Count - 1
dgClient.Rows.Add()
dgClient.Rows(i).Cells("client").Value = dsClient.Tables("TableClient").Rows(i).Item("Client")
dgClient.Rows(i).Cells("comments").Value = dsClient.Tables("TableClient").Rows(i).Item("Comments")
Next
How I can do above using C#
Thanks in advance
Please solve my Problem:
I have DataGridView and Dataset. I want to add data from dataset to datagridview row by row and not by using DataGridView.DataSource method.
For ex. following is the way to do the same using Vb.net
dgClient.Columns.Add("client", "Client")
dgClient.Columns("client").Width = 150
dgClient.Columns.Add("comments", "Comments")
dgClient.Columns("comments").Width = 250
Dim i As Integer
For i = 0 To dsClient.Tables("TableClient").Rows.Count - 1
dgClient.Rows.Add()
dgClient.Rows(i).Cells("client").Value = dsClient.Tables("TableClient").Rows(i).Item("Client")
dgClient.Rows(i).Cells("comments").Value = dsClient.Tables("TableClient").Rows(i).Item("Comments")
Next
How I can do above using C#
Thanks in advance
•
•
Join Date: Jun 2006
Posts: 1
Reputation:
Solved Threads: 0
•
•
•
•
Hi all,
Please solve my Problem:
I have DataGridView and Dataset. I want to add data from dataset to datagridview row by row and not by using DataGridView.DataSource method.
For ex. following is the way to do the same using Vb.net
dgClient.Columns.Add("client", "Client")
dgClient.Columns("client").Width = 150
dgClient.Columns.Add("comments", "Comments")
dgClient.Columns("comments").Width = 250
Dim i As Integer
For i = 0 To dsClient.Tables("TableClient").Rows.Count - 1
dgClient.Rows.Add()
dgClient.Rows(i).Cells("client").Value = dsClient.Tables("TableClient").Rows(i).Item("Client")
dgClient.Rows(i).Cells("comments").Value = dsClient.Tables("TableClient").Rows(i).Item("Comments")
Next
How I can do above using C#
Thanks in advance
See www.akadia.com/services/dotnet_databinding.html
See ya
edreflak
•
•
Join Date: Dec 2008
Posts: 1
Reputation:
Solved Threads: 0
here is the equivalent code that u have given in VB, but plz plz this is my first time that i have writen code for the datagridview in C#. i m begginer too, to seach and learn abt datagridview when i found your problem so i tried on it . if it is correct so plz tell me. otherwise sorry for disturbing u .
c# Syntax (Toggle Plain Text)
conString = "Data Source=(local);Initial Catalog=Northwind;Integrated Security=True"; con = new SqlConnection(conString); con.Open(); string quryString = " select * from Employees"; da = new SqlDataAdapter(quryString, con); ds = new DataSet(); da.Fill(ds, "Emp"); //dataGridView1.DataSource = ds.Tables["Emp"]; dataGridView1.Columns.Add("EmpID", "ID"); dataGridView1.Columns.Add("FirstName", "FirstName"); dataGridView1.Columns.Add("LastName", "LastName"); int row = ds.Tables["Emp"].Rows.Count - 1; for (int r = 0; r<= row; r++) { dataGridView1.Rows.Add(); dataGridView1.Rows[r].Cells[0].Value = ds.Tables["Emp"].Rows[r].ItemArray[0]; dataGridView1.Rows[r].Cells[1].Value = ds.Tables["Emp"].Rows[r].ItemArray[1]; dataGridView1.Rows[r].Cells[2].Value = ds.Tables["Emp"].Rows[r].ItemArray[2]; } con.Close(); }
Last edited by Ancient Dragon; Jul 3rd, 2009 at 1:59 pm. Reason: add code tags
![]() |
Similar Threads
- Crystal Report & Code based Dataset (VB.NET)
- DataGridView Column Cell Style Formatting (C#)
- retrieve data by VB.Net (VB.NET)
- how to adding data in dataset (ASP.NET)
- Problem adding rows to database (C#)
- how to add rows to the child grid (ASP.NET)
- sending the number of rows...... (HTML and CSS)
- 2 ASP Questions (ASP.NET)
Other Threads in the C# Forum
- Previous Thread: how to detect previously installed components?
- Next Thread: NullReferenceException Error
| Thread Tools | Search this Thread |
.net access algorithm alignment app application array bitmap box c# c#gridviewcolumn check checkbox client color combo combobox communication concurrency control conversion csharp custom data database datagrid datagridview dataset datatable datetime degrees draganddrop drawing enabled encryption enum excel file focus form format forms function gdi+ getoutlookcontactusinfcsvfile globalization hospitalmanagementsystem image input install java list localization mandelbroth math messagebox microsoftc#visualexpress mono mouseclick mysql operator path photoshop picturebox pixelinversion plotting pointer post programming radians read regex remote remoting richtextbox save server sleep socket sql sql-server statistics string stringformatting sun table text textbox thread time timer update usercontrol validate validation visualstudio webbrowser winforms wpf xml





