PC Review
Forums
Newsgroups
Microsoft DotNet
Microsoft ADO .NET
Populating a datagrid
Forums
Newsgroups
Microsoft DotNet
Microsoft ADO .NET
Populating a datagrid
![]() |
Populating a datagrid |
|
|
Thread Tools | Rate Thread |
|
|
#1 |
|
Guest
Posts: n/a
|
Hi,
I have a datagrid on a WinForm which I need to poulate with a search result set. The search is done with a parameter to a sp so I'm guessing the data grid can't be bound to a design time Dataset. I have no idea where to start with this. I have created a datareader which holds all the returned rows from the query. How can I load what's in the data reader into the datagrid, or must I use some other way? Thank you very much for any suggestions Ant |
|
|
|
#2 |
|
Guest
Posts: n/a
|
Well, you aren't so far off. Instead of the datareader, use your sp to
populate a datatable within a dataset and bind that to your datagrid. "Ant" <Ant@discussions.microsoft.com> wrote in message news:76827F8B-11D0-4B79-852C-9857BEB04F03@microsoft.com... > Hi, > I have a datagrid on a WinForm which I need to poulate with a search > result > set. > The search is done with a parameter to a sp so I'm guessing the data grid > can't be bound to a design time Dataset. I have no idea where to start > with > this. > > I have created a datareader which holds all the returned rows from the > query. How can I load what's in the data reader into the datagrid, or must > I > use some other way? > > Thank you very much for any suggestions > Ant > > |
|
|
|
#3 |
|
Guest
Posts: n/a
|
Thanks very much Earl. I'm quite new to ADO.NET.
I know this is wrong, but I don't know how to execute a command against a datatable: DataSet dsResults = new DataSet(); DataTable dtResults = dsResults.Tables.Add("resultTable"); sqlConnection1.Open(); // This is not right. How is this done?? dsResults.Tables["resultTable"] = (DataTable)comSearchByName.ExecuteReader(); Thanks for any further input. Regards Ant "Earl" wrote: > Well, you aren't so far off. Instead of the datareader, use your sp to > populate a datatable within a dataset and bind that to your datagrid. > > "Ant" <Ant@discussions.microsoft.com> wrote in message > news:76827F8B-11D0-4B79-852C-9857BEB04F03@microsoft.com... > > Hi, > > I have a datagrid on a WinForm which I need to poulate with a search > > result > > set. > > The search is done with a parameter to a sp so I'm guessing the data grid > > can't be bound to a design time Dataset. I have no idea where to start > > with > > this. > > > > I have created a datareader which holds all the returned rows from the > > query. How can I load what's in the data reader into the datagrid, or must > > I > > use some other way? > > > > Thank you very much for any suggestions > > Ant > > > > > > > |
|
|
|
#4 |
|
Guest
Posts: n/a
|
Ant,
Yesterday I have asked you what you where using with an almost the same question (A webform or a windowsform datagrid). I wrote that you cannot use for a windowsform datagrid a datareader as datasource. You told that you where using a webform, than I gave you a sample for a datasource and a binding with a sqldatareader. Now you ask the same however for a windowform with a datareader What is your goal with asking these answered questions? Cor |
|
|
|
#5 |
|
Guest
Posts: n/a
|
Sorry Cor,
I now simply need to know how to load data from a command into a dataset. Below is what I'm trying to do. Do you have any suggestions on how I would do this properly? // I need to return the result set into the resultSet table dsResults.Tables["resultTable"] = (DataTable)comSearchByName.ExecuteReader(); Thanks for your help Ant "Cor Ligthert [MVP]" wrote: > Ant, > > Yesterday I have asked you what you where using with an almost the same > question (A webform or a windowsform datagrid). > > I wrote that you cannot use for a windowsform datagrid a datareader as > datasource. > > You told that you where using a webform, than I gave you a sample for a > datasource and a binding with a sqldatareader. > > Now you ask the same however for a windowform with a datareader > > What is your goal with asking these answered questions? > > Cor > > > |
|
|
|
#6 |
|
Guest
Posts: n/a
|
Ant,
The datagrid is typical for version 2002/2003 your code is a new part of 2005. What is it that you are using? Cor |
|
|
|
#7 |
|
Guest
Posts: n/a
|
Hi Cor,
Thanks for your interest, I'm using visual studio 2003. I got the code from MSDN. I think the problem however is more to do with my lack of knowledge with ADO. I've only started using it recently & am trying to learn as much as possble. Hence, if you were using a command object to load data into a table in a data set, how would you do it. Just a code example would be very helpful. // What I'm doing dsResults.Tables["resultTable"] = comSearchByName.ExecuteReader(); // How you do this goes here... Thanks Ant "Cor Ligthert [MVP]" wrote: > Ant, > > The datagrid is typical for version 2002/2003 your code is a new part of > 2005. > > What is it that you are using? > > Cor > > > |
|
|
|
#8 |
|
Guest
Posts: n/a
|
An,
\\\ DataTable dt = new DataTable(); SQLConnection conn = new SqlConnection("Server=(Local);" & _ "DataBase=Northwind; Integrated Security=SSPI"); string sqlstr = "SELECT * FROM Employees"; SqlDataAdapter da = New SqlDataAdapter(sqlstr, conn); da.Fill(dt); DataGridView1.DataSource = dt; /// I hope this helps, cor |
|
|
|
#9 |
|
Guest
Posts: n/a
|
Hi Cor,
Thanks greatly for your help. I'm using a sp. I tried the sp instead of the string that you suppled in the dataAdapter like so: SqlDataAdapter da = new SqlDataAdapter(comSearchByName,sqlConnection1); but received an error: Cannot convert from System.Data.SqlClient.SQLCommand to string How do I get around this problem? Thanks very mucvh for your help on this Ant "Cor Ligthert [MVP]" wrote: > An, > \\\ > > DataTable dt = new DataTable(); > SQLConnection conn = new SqlConnection("Server=(Local);" & _ > "DataBase=Northwind; Integrated Security=SSPI"); > string sqlstr = "SELECT * FROM Employees"; > SqlDataAdapter da = New SqlDataAdapter(sqlstr, conn); > da.Fill(dt); > DataGridView1.DataSource = dt; > /// > > I hope this helps, > > cor > > > |
|
![]() |
|
| Thread Tools | |
| Rate This Thread | |
|
|

Main Page 

