How to render PivotGrid component in SQL database with .NET WebForms?
This KB document explains how to render Pivot component from SQL Database using VB.
Solution:
You can render Pivot components (in relational server mode) in VB by using DataTable as DataSource. You can also perform the operations supported by respective Pivot controls. The following code samples demonstrate this.
Step 1
In Relational WebAPI controller, add the following class. Using the GetSQLResult method, you can get the data from local database.
''' Local Database Connection Public Class DbaseQuery Public Function GetSQLResult() Dim conSTR As String = "Data Source=(LocalDB)\MSSQLLocalDB;AttachDbFilename=" & AppDomain.CurrentDomain.BaseDirectory & "App_Data\Database1.mdf;Integrated Security=True" Dim xquery As String = "SELECT * FROM table1" Dim sqlConn As SqlConnection = New SqlConnection(conSTR) sqlConn.Open() Dim cmd As SqlCommand = New SqlCommand(xquery, sqlConn) Dim da As SqlDataAdapter = New SqlDataAdapter(cmd) Dim dt As DataTable = New DataTable() da.Fill(dt) For i = 0 To dt.Rows.Count - 1 For j = 0 To dt.Rows(i).ItemArray.Length - 1 dt.Rows(i).ItemArray(j) = dt.Rows(i).ItemArray(j).ToString().Trim() Next Next Return dt End Function End Class
Step 2
Add the following namespace.
Imports System.Data.SqlClient
Step 3
Pass the above DataTable as parameter, which is returned from the GetSQLResult method, in every action like InitializeClient, FetchMembers, nodeDropped, etc., of respective Pivot component.
Public Class RelationalGridController Inherits ApiController Dim dbquery As DbaseQuery = New DbaseQuery() <System.Web.Http.ActionName("InitializeGrid")> _ <System.Web.Http.HttpPost> _ Public Function InitializeGrid(jsonResult As Dictionary(Of String, Object)) As Dictionary(Of String, Object) //… dict = htmlHelper.GetJsonData(jsonResult("action").ToString(), dbquery.GetSQLResult()) Return dict End Function <System.Web.Http.ActionName("FetchMembers")> _ <System.Web.Http.HttpPost> _ Public Function FetchMembers(jsonResult As Dictionary(Of String, Object)) As Dictionary(Of String, Object) //… dict = htmlHelper.GetJsonData(jsonResult("action").ToString(), dbquery.GetSQLResult(), jsonResult("headerTag").ToString(), jsonResult("sortedHeaders").ToString()) Return dict End Function //….
Note:
A new version of Essential Studio for ASP.NET is available. Versions prior to the release of Essential Studio 2014, Volume 2 will now be referred to as a classic versions.The new ASP.NET suite is powered by Essential Studio for JavaScript providing client-side rendering of HTML 5-JavaScript controls, offering better performance, and better support for touch interactivity. The new version includes all the features of the old version, so migration is easy.
The Classic controls can be used in existing projects; however, if you are starting a new project, we recommend using the latest version of Essential Studio for ASP.NET. Although Syncfusion will continue to support all Classic Versions, we are happy to assist you in migrating to the newest edition.
For current customers, you can check out our components from the License and Downloads page. If you are new to Syncfusion, you can try our 30-day free trial to check out our other controls. If you have any queries or require clarifications, please let us know in the comments section below.
You can also contact us through our support forums, Direct-Trac, or feedback portal. We are always happy to assist you!