Trying to load grid from database

Tags: #<Tag:0x00007efc6d2e9bc0>

Here is my controller code to get data from database.

public JsonResult getACLog()
    {
        var log = new List<ACLog>();
        
        OdbcCommand command = new OdbcCommand("SELECT fldPrimaryKey, fldCall, fldDateStr, fldTimeOnStr, fldMode, fldState, fldRstR, fldRstS, fldBand FROM tblContacts;");
        using (OdbcConnection connection = new OdbcConnection("Driver={Driver do Microsoft Access (*.mdb)};dbq=C:\\Users\\User\\MasterLog.mdb;defaultdir=C:\\Users\\User;driverid=25;fil=MS Access;filedsn=C:\\Users\\User\\MasterLog.mdb.dsn;maxbuffersize=2048;maxscanrows=8;pagetimeout=5;safetransactions=0;threads=3;uid=admin;usercommitsync=Yes"))
        {
            command.Connection = connection;
            connection.Open();
            using (var reader = command.ExecuteReader())
            {
                while (reader.Read())
                {
                    var logger = new ACLog();

                    logger.box = "false";
                    logger.fldPrimaryKey = (reader.SafeGetInt(0).ToString());
                    logger.fldCall = reader.SafeGetString(1);
                    logger.fldDateStr = reader.SafeGetString(2);
                    logger.fldTimeOnStr = reader.SafeGetString(3);
                    logger.fldMode = reader.SafeGetString(4);
                    logger.fldState = reader.SafeGetString(5);
                    logger.fldRstR = reader.SafeGetString(6);
                    logger.fldRstS = reader.SafeGetString(7);
                    logger.fldBand = reader.SafeGetString(8);
                    

                    log.Add(logger);
                }
            };
        }

        return Json(log, JsonRequestBehavior.AllowGet);
    }
I can se the data in the "log" statement but I get a popup box with " Local says error". Is there something wrong with my controller routine or is it a handsontable problem. My database has about 17,600 rows.

Hi @joannplano2005

It seems that this is not enough data to help.

Could you tell me what your environment is and share your Handsontable configuration? Handsontable has its own API for data alteration, so it might be the thing here.

I am using Win 11, VS2015, and my Handsontable configuration is
var
$$ = function(id) {return document.getElementById(id);},
container = $$(‘example1’),
exampleConsole = $$(‘example1console’),
autosave = $$(‘autosave’),
save = $$(‘save’),
load = $$(‘load’),
autosaveNotification,
hot;

hot = new Handsontable(container, {
    startRows: 8,
    startCols: 10,
    rowHeaders: true,
    //colHeaders: true,
    columnSorting: true,
    colHeaders: ['row', 'Id', 'Call', 'Date', 'Time', 'Band', 'Mode', 'State', 'RstR', 'RstS'],
    dataSchema: { row: null, id: null, Call: null, Date: null, Time: null, Band: null, Mode: null, State: null, RstR: null, RstS: null },
    columns: [
               { data: 0, type: 'checkbox' },
               { data: 1 },
               { data: 2 },
               { data: 3 },
               { data: 4 },
               { data: 5 },
               { data: 6 },
               { data: 7 },
               { data: 8 },
               { data: 9 }
    ],

    licenseKey: 'non-commercial-and-evaluation',

and the Load routine is
// GET method gets data from the Controller
Handsontable.dom.addEvent(load, ‘click’, function () {
jQuery.ajax({
url: ‘/Home/GetACLog’, //Controller to Get the
//JsonResult From – Json(jsonData, JsonRequestBehavior.AllowGet);
type: “GET”,
dataType: “json”,
contentType: ‘application/json; charset=utf-8’, // dataType and contentType should be json
async: true,
processData: false,
cache: false,
success: function (data) { // on Success send the Json data
// to the table by using loaddata function""
//alert(data);
hot.loadData(data);
exampleConsole.innerHTML = ‘Data loaded’;
},
error: function (xhr) {
alert(‘error’);
}
});

Thank you for sharing. Generally, it seems that it would be better to use the afterInit hook here. We do not provide support for the use of helpers.

Could you

  1. Copy the full error message
  2. Specify if the schema follows the key structure of the JSON data you’d like to parse and pass to Handsontable

Hi @joannplano2005

we haven’t got an update to this thread for more than a month. I need to close it.

If there’s anything still missing please feel free to open a new thread.