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:
$("#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