We use cookies to give you the best experience on our website. If you continue to browse, then you agree to our privacy policy and cookie policy. Image for the cookie policy date

SpreadSheet - save content to database table

ASP.NET Web Forms with VB.NET code.

I have a database table Addresses. How can I use the ej:Spreadsheet component to let the user import addresses to the Addresses table on the database server?

I've made the ASPX page with the ej:Spreadsheet and the AJAX script to upload the spreadsheet to my ASMX webservice:

AJAX script:
        // Save the Spreadsheet data As JSON and send to webservice
        $("#saveSpreadsheetToDatabase").bind("click", function () {
            $.ajax({
                type: "POST",
                url: "Handlers/SpreadsheetFeatures.asmx/SaveSpreadsheetToDB",
                data: JSON.stringify({ sheetData: $("#MainContent_exAddress").ejSpreadsheet("saveAsJSON") }),
                contentType: "application/json; charset=utf-8",
                dataType: 'json',
                success: function (data) {
                    // Success code here.
                    alert("Import succeeded");
                },
                error: function (xhr, status) {
                    alert("An error occurred: " + status);
                }
            });
        });

How can I capture in the ASMX webservice the rows and columns from the sheetData JSON string to insert the data to the Addresses table? The Column names in the spreadsheet have the same name als the table columns.

Table structure:
CREATE TABLE [dbo].[Addresses] (
    [AddressID]   NUMERIC (18)   IDENTITY (1, 1) NOT NULL,
    [Name]        NVARCHAR (255) NULL,
    [IZ]          NVARCHAR (255) NULL,
    [Street]      NVARCHAR (255) NULL,
    [City]        NVARCHAR (255) NULL,
    [PC]          NVARCHAR (50)  NULL,
    [Country]     NVARCHAR (50)  NULL,
    [Phone]       NVARCHAR (50)  NULL,
    [Email]       NVARCHAR (255) NULL,
    [CustomerITG] INT            NOT NULL,
    [Lat]         NVARCHAR (50)  NULL,
    [Lng]         NVARCHAR (50)  NULL,
    [Comment]     NTEXT          NULL,
    CONSTRAINT [PK_Addresses] PRIMARY KEY NONCLUSTERED ([AddressID] ASC)
);

ASPX WebMethod
    <WebMethod()>
    Public Sub SaveSpreadsheetToDB(ByVal sheetData As String)
        Try
            'Insert sheetData to SQL database
        Catch ex As Exception

        End Try
    End Sub



1 Reply

MV Madhan Venkateshan Syncfusion Team December 24, 2019 03:29 PM UTC

Hi Peter, 
 
Good day to you. 
 
We would you like to inform that we have already documented your reported query, please refer the below KB link. 
 
 
If you trying to save it as JSON to server, please refer the below KB link. 
 
If we misunderstood your requirement, please share more details. So that we can work on this and provide you a better solution quickly. 
 
Regards, 
Madhan V 


Loader.
Live Chat Icon For mobile
Up arrow icon