| | |
How to add rows from dataset to datagridview
Please support our C# advertiser: Intel Parallel Studio Home
![]() |
•
•
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
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
C# Syntax (Toggle Plain Text)
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
Last edited by niek_e; 7 Days Ago at 10:31 am. Reason: Add code-tags
•
•
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 array asp barchart bitmap box broadcast buttons c# check checkbox client column combobox control conversion csharp custom database datagrid datagridview dataset datetime degrees development display draganddrop drawing encryption enum equation event excel file form format formbox forms formupdate function gdi+ httpwebrequest image index input install java label linux list listbox mandelbrot math mouseclick mysql networking operator packaging parse path photoshop picturebox pixelinversion post powerpacks programming radians regex remote remoting reporting richtextbox robot server sleep socket sql statistics stream string table text textbox thread time timer transform treeview update usercontrol validation visualstudio webbrowser wfa windows winforms wpf xml





