all groups > dotnet windows forms > february 2004 >
You're in the

dotnet windows forms

group:

get data from query?


Re: get data from query? Dmitriy Lapshin [C# / .NET MVP]
2/12/2004 11:00:52 AM
dotnet windows forms:
Hi,

You should configure an OleDbCommand, specifying the name of the query as
the CommandText and setting the CommandType to StoredProcedure. Then, set
this command as the SelectCommand for an OleDbDataAdapter and use it's Fill
method to populate the table in the dataset.

The above obviously assumes you have a configured OleDbConnection to the MS
Access database.

--
Dmitriy Lapshin [C# / .NET MVP]
X-Unity Test Studio
http://www.x-unity.net/teststudio.aspx
Bring the power of unit testing to VS .NET IDE

[quoted text, click to view]
get data from query? Graeme
2/12/2004 9:48:42 PM
Hi

How do I get data from an MS Access QUERY rather than a table? Below works
OK for a table ...
Dim myFeedersTable As DataTable = myFeedersDS.Tables("Network_Data_Feeder")

Tried a few things, but no go.

Thanks
Graeme

Re: get data from query? Dmitriy Lapshin [C# / .NET MVP]
2/13/2004 10:21:56 AM
Graeme,

[quoted text, click to view]

Since you bind the grid to a dataset, you have to specify the DataMember
property value as well. You can do so by using the SetDataBinding method:

DataGrid1.SetDataBinding(myFeedersDS, "tempgnm")

P.S.: you don't need to open and close the connection manually when you use
the DataAdapter. It manages the connection state automatically behind the
scenes.

--
Dmitriy Lapshin [C# / .NET MVP]
X-Unity Test Studio
http://www.x-unity.net/teststudio.aspx
Bring the power of unit testing to VS .NET IDE

[quoted text, click to view]
Re: get data from query? Graeme
2/13/2004 12:46:12 PM
Thanks Dmitriy. This is what I did ...

Private Sub FillGrid_Click(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles FillGrid.Click

Dim myFeedersDA As OleDbDataAdapter = New OleDbDataAdapter()

Dim myFeedersDS As DataSet = New DataSet()

Dim myConnectString As OleDbConnection = New
OleDbConnection("Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" &
tbxDataPath.Text)

Dim myFeedersSQL As OleDbCommand = New OleDbCommand("tempgnm",
myConnectString)

myFeedersSQL.CommandType = CommandType.StoredProcedure

myFeedersSQL.CommandTimeout = 30

myFeedersDA.SelectCommand = myFeedersSQL

myConnectString.Open()

myFeedersDA.Fill(myFeedersDS, "tempgnm")

myConnectString.Close()

DataGrid1.DataSource = myFeedersDS

End Sub

This displays headers in grid, but no data - Only one row displays as (null)
and my other records don't display at all.

Can you or anyone else help further?
Thanks again
Graeme

[quoted text, click to view]

Re: get data from query? Graeme
2/16/2004 10:28:37 PM
Thanks Dmitriy. I'll get on with it tomorrow!
[quoted text, click to view]

AddThis Social Bookmark Button