0

My goal is to return a C# SQLDataReader object from a C# function into a JavaScript.

In the JavaScript part I would like to read String-Values from the DataReader.

Is this possible?

This is how I tested:

var tools = Tools.GetExtension("LoadTheNETAssembly");
reader = tools.ExecProcedure("exec Loc.dbo.spASTVSwitch '" + sExtension + "', '" + sChannel + "'");

So I called the "ExecProcedure" Function in the C# Code.

This works, but I do not know how to handle the returned SQLDataReader.

In the past I returned a ADODB-Connection object from a Delphi-Function into JavaScript.

This worked perfectly and I would like to replace the Delphi-Part by C#.

6
  • 1
    Don't return the reader object, read the data server-side and then return the data (e.g. formatted as JSON) and then let JS process it. JS cannot understand a server-side C# object anyhow, there's just no equivalence between the two languages (besides, how would you transmit such a thing over the wire), what you're suggesting doesn't make a lot of sense. Even if you could, once the reader object arrived in the browser, it would no longer have access to the database, and how would you call its methods and properties? Again you can't run C# methods from within JS, it's just nonsensical. Commented Jan 2, 2018 at 10:37
  • 1
    Sounds like you're talking about creating a COM object in .net. Commented Jan 2, 2018 at 10:37
  • But how could we do that with a ADOConnection object in Delphi then? Yes that is correct, i am creating a COM object. Commented Jan 2, 2018 at 10:38
  • 2
    This is pretty old-school. Can you elaborate on why you need to do this? Maybe there is a better way. If not maybe start here stackoverflow.com/questions/3232242/… Commented Jan 2, 2018 at 10:40
  • We have a system that has to be pretty flexible. There is a so called "handler", which is written in JavaScript and from this handler, we call the different operations. For example in this case, to read data from an SQL Server and to evaluate some values. Commented Jan 2, 2018 at 10:43

1 Answer 1

1

I have made a app in winforms where I made all pages in static html,css,javascript. I need to bind my javascript based list from the app where my whole backend code in c#. I simply done ComVisibleAttribute(True) on the page. My C# code expose a StringBuilder that have all the result.

I simply call .ToString() from javascript on that object and I can see the response in javacript. Same time my Breakpoint hits in C# (.cs code) so this is how I get my work done as I want.

In your situation you are calling C# code from your JavaScript code. You can expose every object (which is public) to the Javascript Code. For example read this article https://www.codeproject.com/Articles/35373/VB-NET-C-and-JavaScript-communication

You can call your C# object from Javascript something like this

window.external.reader.MyFunction()

Remember that object that you want to use in c# should be publicly accessible and must be static.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.