.Net, ADO.NET, ASP.NET, C#, DataSet, DataTable, Example Connection, GridView, Programming, Visual Studio 2010, Web Development, WebForms

C# Example of a GridView Tied to a SQLDataSource

GridView Example
GridView Example

So what’s the simplest way to build a Web-based interface for a basic database table? In this article I’ll provide a fully working example with a minimum of code.

This is a useful feature to be able to put together, especially when you are catering to power users who should be able to help maintain their own data without needing to call you each time. Continue reading “C# Example of a GridView Tied to a SQLDataSource”

.Net, ADO.NET, ASP.NET, C#, Database, DataSet, DataTable, DB Connection Example, Programming, SQLDataAdapter, VB.NET, Web Development

ASP.NET Example – Populating a DataSet Using SQLDataAdapter Fill DataSet

In the example functions below I’m illustrating how to set up a basic query to a stored procedure in your database that takes a single string parameter. The examples involve using the SQLDataAdapter object to Fill a DataSet. The resulting DataTable can then be queried as desired. Specifically:

  1. The first example shows how to read the first row of the results after your Datatable has been populated. I provide the same example in VB.NET and C#.
  2. The second example shows how to loop through the results if you anticipate multiple returned rows. As before,  I provide the same example in VB.NET and C#.

As part of this code, remember to include the correct .NET Namespaces. If you are writing your code inline (in either VB.NET or C#), use:

<%@ Import Namespace="System.Data" %>
<%@ Import Namespace="System.Data.SqlClient" %>

and if you are writing your code in codebehind, use:

VB Codebehind:

Imports System.Data
Imports System.Data.SqlClient

C# Codebehind:

using System.Data;
using System.Data.SqlClient;

Also, navigate here if you are interested in further articles I have written about ADO in .NET.

Continue reading “ASP.NET Example – Populating a DataSet Using SQLDataAdapter Fill DataSet”