Dynamicweb 8 Documentation
CreateDataSet(String) Method
Example 

The SQL specifiyng the data to return in dataset
Creates a System.Data.DataSet with data returned by the passed SQL statement. Can only be called once per instance. Use multiple objects when your logic requires working with multiple connected datasets. Allthough the Finalize methods calls Dispose, thereby enabling the GC to clean up unmanaged code, call Dispose on your DataManager object as soon as your are done.
Syntax
'Declaration
 
Public Overloads Function CreateDataSet( _ 
   ByVal sql As String _ 
) As DataSet
public DataSet CreateDataSet( 
   string sql 
)

Parameters

sql
The SQL specifiyng the data to return in dataset

Return Value

A connected System.Data.DataSet instance with data.
Remarks
Connects to the default database. Dynamic.mdb in /Database if the solution is running MS Access, or the SQL-Server database if the solution is running MS SQL-Server.
Example
Updating data in the databaseUpdating data in the database
using System.Data;

namespace Dynamicweb.Examples.CSharp
{
class DataManagerSample
{
    public int Save(int id)
    {
        //Create a new datamanager instance
        using (var dtm = new DataManager())
        {
            //Create a dataset with zero, one or more rows to update.
            var ds = dtm.CreateDataSet("SELECT * FROM UrlPath WHERE UrlPathID=" + id, "Dynamic.mdb");
            DataRow row;

            //If the id is 0, there will be no records in the returned dataset
            if (id == 0)
            {
                //Add a new row to the table in the dataset
                row = ds.Tables[0].NewRow();
                ds.Tables[0].Rows.Add(row);
                //Set column values that only needs to be set on new rows
                row["UrlPathCreated"] = System.DateTime.Now;
            }
            else
            {
                //We had a record in the table
                row = ds.Tables[0].Rows[0];
            }

            //Update the column values
            row["UrlPathPath"] = "Contact";
            row["UrlPathRedirect"] = "Default.aspx?ID=1";
            row["UrlPathStatus"] = 301;
            row["UrlPathUpdated"] = System.DateTime.Now;
            row["UrlPathActive"] = true;

            //Pass the dataset to the datamanagers UpdateDataset method that will commit our changes to the database
            dtm.Update(ds);

            //If the id is 0, it was a new record - GetIdentity will return the id of the newest row added.
            if (id == 0)
            {
                id = dtm.GetAddedIdentityKey();
            }

            //Dispose the dataset
            ds.Dispose();
        }
        return id;
    }

}
}
Public Class DataManagerSample
    Public Function Save(ByVal id As Integer) As Integer
        'Create a new datamanager instance
        Using dtm As New DataManager
            'Create a dataset with zero, one or more rows to update.
            Dim ds As DataSet = dtm.CreateDataSet("SELECT * FROM UrlPath WHERE UrlPathID=" & id, "Dynamic.mdb")
            Dim row As DataRow

            'If the id is 0, there will be no records in the returned dataset
            If id = 0 Then
                'Add a new row to the table in the dataset
                row = ds.Tables(0).NewRow()
                ds.Tables(0).Rows.Add(row)
                'Set column values that only needs to be set on new rows
                row("UrlPathCreated") = Now
            Else
                'We had a record in the table
                row = ds.Tables(0).Rows(0)
            End If

            'Update the column values
            row("UrlPathPath") = "Contact"
            row("UrlPathRedirect") = "Default.aspx?ID=1"
            row("UrlPathStatus") = 301
            row("UrlPathUpdated") = Now
            row("UrlPathActive") = True

            'Pass the dataset to the datamanagers UpdateDataset method that will commit our changes to the database
            dtm.Update(ds)

            'If the id is 0, it was a new record - GetIdentity will return the id of the newest row added.
            If id = 0 Then
                id = dtm.GetAddedIdentityKey()
            End If

            'Dispose the dataset
            ds.Dispose()
        End Using
        Return id
    End Function
End Class
Requirements

Target Platforms: Windows 7, Windows Vista SP1 or later, Windows XP SP3, Windows Server 2008 (Server Core not supported), Windows Server 2008 R2 (Server Core supported with SP1 or later), Windows Server 2003 SP2

See Also

Reference

DataManager Class
DataManager Members
Overload List

Send Feedback