Has C# a cursor data type

BenTam 1,761 Reputation points
2023-07-23T08:20:29.26+00:00

Dear All,

I am converting a Visual FoxPro (VFP) program to a C# program. In VFP there is a data type "Cursor" (with columns and rows) to store data retrieved from SQL Server. Has C# a similar data type?

For example, the following screen capture is a "Date Schedule form" from my old VFP program. Data enclosed by the red line is a single select from the SQL server to a VFP cursor. Then I extract the morning, afternoon, and evening courses from the cursor and put them in the slots. That will minimize the traffic between the client and the SQL server.

VFP DateSehedule

C#
C#
An object-oriented and type-safe programming language that has its roots in the C family of languages and includes support for component-oriented programming.
11,317 questions
{count} votes

4 answers

Sort by: Most helpful
  1. Fabio Caruso 90 Reputation points
    2023-07-31T14:25:47+00:00

    Hi,

    if You want a graphical interface like Cursor of VFP, in C# the best choice is DataGrid if You are using WPF (Windows Presentation Foundation), or DataGridView if You are using Windows Forms.

    Developing your C# code, the steps to join a DataGrid graphical object to your SQL Database are as follows:

    1. In Visual Studio, create a new WPF Project, and drag a new Datagrid graphical object from Visual Studio Toolbox;
    2. Open a Sql connection to your database;
    3. Create an istance of SqlDataAdapter class to issue your SELECT Sql command and retrieve your data from the database;
    4. Create a new istance of DataTable class, and issue a fill command to fill the datatable with data retrieved from the DataAdapter;
    5. Set the DataSource property of your DataGrid to that Datatable, so all your data will be show in your new DataGrid.
    6. Enjoy.

    Also make the consideration that the communication between the DataGrid and your Sql Database can be made in Two-Way mode...

    1 person found this answer helpful.

  2. Sander van de Velde | MVP 35,246 Reputation points MVP
    2023-07-23T12:24:39.9633333+00:00

    Hello @BenTam-3003 ,

    The cursors you used are a SQL Server database concept.

    There is not much Sql Server documentation available about using them in programming languages.

    This post about using cursors in Entity Framework seems helpful though.

    MS Learn offers a number of free training modules regarding Entity Framework Core.


    If the response helped, do "Accept Answer". If it doesn't work, please let us know the progress. All community members with similar issues will benefit by doing so. Your contribution is highly appreciated.


  3. Olaf Helper 46,196 Reputation points
    2023-07-24T07:27:27.5566667+00:00

  4. Bruce (SqlWork.com) 71,696 Reputation points
    2023-08-01T21:31:05.9933333+00:00

    VFP was designed as a database tool. It has data aware controls which support paging. C# does not have any intrinsic database or forms support.

    C# currently has 3 popular form libraries, Winforms, WPF and Maui. These libraries are general purpose. They have lists/grids that bind to data collections, which can come from a database, but you code the database access separately. you will also need implement paging and supply a paging ui if you need paging as in your sample. the same is true for filtering and sorting.

    you also can bind control to a model, but it is not database aware, you will create the crud operations in code.

    you will probably use Entity Framework for database access. This is a completely different model than VFP, and will take some leaning. You other option is the ado library which is lower level.

    There are 3rd party controls for your chosen form library which are more data aware. You will probably want a 3rd party grid. for example see:

    https://www.telerik.com/products/wpf/overview.aspx


Your answer

Answers can be marked as Accepted Answers by the question author, which helps users to know the answer solved the author's problem.