.NET data access with JavaScript

Most of Microsoft’s .NET examples are in VB and C#. For anyone looking for a JScript example of data access using SqlConnection rather than conventional ASP data access, here we are.

// get the connection string from the config file

    var sConn = ConfigurationSettings.AppSettings("Connection String");
    var oConn : SqlConnection = new SqlConnection(sConn);
    oConn.Open();
    var sSQL = your sql string
    try{
        var oCmd : SqlCommand = new SqlCommand(sSQL, oConn);
        var reader = oCmd.ExecuteReader();
        var sReturnString=’’;
        while(reader.Read()){
            sReturnStringt += build up a return string, for example, here
        }
    }catch(e){
        sReturnString =sSQL + ‘ ‘+ e.description; // exception handling
    }
    reader.Close();
    oConn.Close();

Post a Comment

Your email is never published nor shared. Required fields are marked *

*
*