Temporary "cursor"


Author
Message
Trent Taylor
Trent Taylor
StrataFrame Developer (14K reputation)StrataFrame Developer (14K reputation)StrataFrame Developer (14K reputation)StrataFrame Developer (14K reputation)StrataFrame Developer (14K reputation)StrataFrame Developer (14K reputation)StrataFrame Developer (14K reputation)StrataFrame Developer (14K reputation)StrataFrame Developer (14K reputation)
Group: StrataFrame Developers
Posts: 6.6K, Visits: 7K
Well, you can take several approaches. 

Approach #1 - Standard Query
The first approach would just be to execute the query and bring it into a BO.  Remember, you are dealing with disconnected data so you really don't have to add this to a temp cursor as BO (or DataTable within the BO) is your temp cursor.  A query doesn't have to match the structure of the BO...you can bring back any query you want.  So it would look something like this:

MyBO.FillDataTable("SELECT date as xdate,cdesc as Service,SUM(num_pax) FROM tempo1 GROUP BY xdate,Service")


You can then access the populated table via the strong-typed properties...or custom properties...or just by accessing the MyBo.CurrentRow.Item("MyField")

Approach #2 - Multiple Result Sets
Remember that there is a new method on the BusinessLayer that allows you to bring back as many result sets as you need...this is very nice when you need to execute multiple queries:

Dim cmd As New SqlCommand("SELECT date as xdate,cdesc as Service,SUM(num_pax) FROM tempo1 GROUP BY xdate,Service;" & _
    "SELECT CAST(CDOW(xdate)as character(10)) as xday,xdate,Service,sum_num_pax as pax FROM tempo2;")

MicroFour.StrataFrame.Business.BusinessLayer.FillMultipleDataTables(cmd, _
                                                                                             MyBO1, _
                                                                                             MyBO2)

Approach #3 - True Temp Cursors in SQL Server
If you really need to create a temp cursor, then this would be done within a stored procedure but ultimately you would be bringing back a result set like above.  The only difference would be that you have done all of the query work on the SQL Sproc side prior to coming back over to the client.  There are a lot of articles on creating temp tables in SQL Server.  The quick and dirty version is that when you create a table with a # it is a local cursor and when you create a table with a ## it is a global cursor.  But I really don't think that this is the approach that you need so I will not expand much on this.

Hugo R. Figueroa
Hugo R. Figueroa
StrataFrame User (243 reputation)StrataFrame User (243 reputation)StrataFrame User (243 reputation)StrataFrame User (243 reputation)StrataFrame User (243 reputation)StrataFrame User (243 reputation)StrataFrame User (243 reputation)StrataFrame User (243 reputation)StrataFrame User (243 reputation)
Group: StrataFrame Users
Posts: 81, Visits: 3.1K
well how can achieve this code (VFP) in C#

SELECT date as xdate,cdesc as Service,SUM(num_pax) FROM tempo1 GROUP BY xdate,Service INTO CURSOR tempo2

SELECT CAST(CDOW(xdate)as character(10)) as xday,xdate,Service,sum_num_pax as pax FROM tempo2 INTO CURSOR tempo3

browse

I need to use several "cursors" to get the data in the way I want and then use the last one as a source of a datagrid.


Trent Taylor
Trent Taylor
StrataFrame Developer (14K reputation)StrataFrame Developer (14K reputation)StrataFrame Developer (14K reputation)StrataFrame Developer (14K reputation)StrataFrame Developer (14K reputation)StrataFrame Developer (14K reputation)StrataFrame Developer (14K reputation)StrataFrame Developer (14K reputation)StrataFrame Developer (14K reputation)
Group: StrataFrame Developers
Posts: 6.6K, Visits: 7K
As Keith mentioned, you can create a temp cursor by using a BOs GetDataTable method or just manually creating a DataTable and populating as you like.

Dim loTable As New DataTable("MyCursor")
DIm loRow As DataRow

'-- Create your columns
loTable.COlumns.Add("MyFirstColumn",GetType(System.STring))

'-- Add new rows
loRow = loTable.NewRow()
loRow.Item("MyFirstColumn") = "Your value"
loTable.Rows.Add(loRow)


Keith Chisarik
Keith Chisarik
StrataFrame VIP (2.4K reputation)StrataFrame VIP (2.4K reputation)StrataFrame VIP (2.4K reputation)StrataFrame VIP (2.4K reputation)StrataFrame VIP (2.4K reputation)StrataFrame VIP (2.4K reputation)StrataFrame VIP (2.4K reputation)StrataFrame VIP (2.4K reputation)StrataFrame VIP (2.4K reputation)
Group: StrataFrame Users
Posts: 939, Visits: 40K
This was like the second thing I wanted to know when I started .NET, I LOVED cursors.



I use datatables or data views now for lightweight temporary data manipulation.

Keith Chisarik
Chan
Chan
Advanced StrataFrame User (965 reputation)Advanced StrataFrame User (965 reputation)Advanced StrataFrame User (965 reputation)Advanced StrataFrame User (965 reputation)Advanced StrataFrame User (965 reputation)Advanced StrataFrame User (965 reputation)Advanced StrataFrame User (965 reputation)Advanced StrataFrame User (965 reputation)Advanced StrataFrame User (965 reputation)
Group: Forum Members
Posts: 533, Visits: 2K
Hi,

I created purchase invoice data entry form for stock in. I want to allow user to able to transfer item by selecting item records in purchase invoice line items.

My design is that, user can select line item record, click on "Transfer" button. Customized Transfer form will be shown as below:

Location               Cost          Qty
-----------------------------------

The fields above is in un-normalized form. However, my tables are designed in normalized form.

How to have temporary table like VFP cursor for temporary editing?

Thank you

GO

Merge Selected

Merge into selected topic...



Merge into merge target...



Merge into a specific topic ID...




Similar Topics

Reading This Topic

Login

Explore
Messages
Mentions
Search