X# Core - How to send query to Sql Server, get a cursor or table?

This forum is meant for examples of X# code.

Post Reply
Anonymous

X# Core - How to send query to Sql Server, get a cursor or table?

Post by Anonymous »

I'm exploring X# Core as total newbie... Learning a little more by the hour. I am only interested in Core stuff at this point, and have no experience or need of VO related paths.

So, my next step of eye-opening experience in X# would be if I could send a SQL query to my Sql Server instance, and get a cursor (or "table" or "data table" or whatever is it called). Then I want to display those rows in a grid on a WinForm.

So, would I be doing this with X# Core commands/objects, or would it be .Net DataSets and DataTables from ADO.net?

Does Entity Framework 6 from .Net have a place in this X# world? I already know Entity Framework.

I presently hist my Sql Server from FoxPro using SqlExec() command and get back a native FoxPro cursor. I'm trying to find parallel workflows in X# Core or else someone get me going in the right paradigm shift I need to make for X#.
User avatar
lumberjack
Posts: 723
Joined: Fri Sep 25, 2015 3:11 pm

X# Core - How to send query to Sql Server, get a cursor or table?

Post by lumberjack »

mattslay wrote:I'm exploring X# Core as total newbie... only interested in Core stuff at this point

So, my next step of eye-opening experience in X# would be if I could send a SQL query to my Sql Server instance, and get a cursor (or "table" or "data table" or whatever is it called). Then I want to display those rows in a grid on a WinForm.
Yes, with Core you would do it the way you do it in c#. Pseudo-code:

Code: Select all

FUNCTION Start() AS VOID
  LOCAL oForm AS MyForm
  oForm := MyForm{}
  Application.Run(oForm)
RETURN
CLASS MyForm INHERIT Form
  CONSTRUCTOR()
    SUPER() // base() in c#
    SELF:InitializeForm()
  RETURN
  METHOD InitializeForm() AS VOID
    VAR oConn := SqlServerConnection{<InitParameters>}
    VAR oComm := SqlServerCommand{<InitParameters>}
    oComm:CommandText := "select * from mytable where..."
    oComm:Connection:Open()
    VAR rdr := oComm:ExecuteReader()
    WHILE rdr:Read()

    ENDDO
    VAR oGrid := DataGridView{}
    oGrid:DockStyle := DockStyle.Fill
    SELF:SuspendLayout()
    SELF:Controls:Add(oGrid)
    ....
   SELF:ResumeLayout()
   // Bind your grid to the rdr etc.
  RETURN
END CLASS

So, would I be doing this with X# Core commands/objects, or would it be .Net DataSets and DataTables from ADO.net?
Indeed it would be a true .NET way of doing things DbProviderFactory, DbConnection, DbCommand and datasets and datatables..
Does Entity Framework 6 from .Net have a place in this X# world? I already know Entity Framework.
Remember I told you before X# is c# in XBase syntax. If you use ILSpy with the XSharp.Language plug-in, you should be able to view a c# EF assembly decompiled in X#.
I presently hist my Sql Server from FoxPro using SqlExec() command and get back a native FoxPro cursor. I'm trying to find parallel workflows in X# Core or else someone get me going in the right paradigm shift I need to make for X#.
There is a SQLSelect, just search for it in the X# helpfile. It does have a link to the git from the helpfile... Look at the constructor. Although I would go the .NET ADO way.
User avatar
wriedmann
Posts: 3644
Joined: Mon Nov 02, 2015 5:07 pm
Location: Italy

X# Core - How to send query to Sql Server, get a cursor or table?

Post by wriedmann »

Hi Matt,

let me add something: as Johan wrote: X# is in its heart a C# compiler with Xbase syntax (and a lot of language extensions like codeblocks, dynamic arrays and some more).
Therefore you can use all the libraries that are available to C# and VB.NET including ADO.NET and Entity Framework.
Since X# comes from VO, it offers also the VO way to access data: DBServers and the VO SQL Classes complete with VO windows and the relative name based databinding.
And hopefully sometimes (with help from the VFP community) it will also contain the data classes from VFP complete with their window classes.
So, the best way for you may be to use the Entity Framework or the ADO.NET classes.
Wolfgang
P.S. in my new applications I use ADO.NET because I need to address several backends: Oracle, SQL Server, Firebird, SQLite, PostgreSQL, MySQL and Access.
Wolfgang
Wolfgang Riedmann
Meran, South Tyrol, Italy
wolfgang@riedmann.it
https://www.riedmann.it - https://docs.xsharp.it
Post Reply