Home All Groups Group Topic Archive Search About
Author
7 Feb 2006 12:11 AM
Ant
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

Author
7 Feb 2006 2:50 AM
Earl
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.

Show quote
"Ant" <A**@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
>
>
Author
7 Feb 2006 3:42 AM
Ant
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





Show quote
"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" <A**@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
> >
> >
>
>
>
Author
7 Feb 2006 7:10 AM
Cor Ligthert [MVP]
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
Author
7 Feb 2006 7:38 AM
Ant
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

Show quote
"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
>
>
>
Author
7 Feb 2006 7:54 AM
Cor Ligthert [MVP]
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
Author
7 Feb 2006 8:40 AM
Ant
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


Show quote
"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
>
>
>
Author
7 Feb 2006 8:50 AM
Cor Ligthert [MVP]
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
Author
7 Feb 2006 9:28 AM
Ant
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




Show quote
"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
>
>
>

AddThis Social Bookmark Button