none
Regarding DataSet RRS feed

  • Question

  • Hi,

     

    In my web application I wan't to create a DataSet that has no connection to a database. But I wan't to fill that DataSet with information structured as a relational database with tables. I don't know how to do that! Maybe somebody can help me with this?

     

     

    Tuesday, September 18, 2007 8:14 AM

All replies

  • Here is a MSDN article to help start with writing dataset without any underlying database

    http://msdn2.microsoft.com/en-us/library/system.data.datatable(VS.80).aspx

     

    Tuesday, September 18, 2007 8:55 AM


  • H u can use datatable.
    Ex:
    imports system.data

     Dim tb As New DataTable("emp")
            Dim c1 As New DataColumn("eno")
            c1.DataType = GetType(Int16)
            tb.Columns.Add(c1)
            Dim c2 As New DataColumn("ename", GetType(String))
            tb.Columns.Add(c2)
            Dim c3 As New DataColumn("sal", GetType(Int32))
            tb.Columns.Add(c3)
            tb.PrimaryKey = New DataColumn() {c1}
            Dim row As DataRow = tb.NewRow
            row(0) = 100 : row(1) = "Pranav" : row(2) = 5000
            tb.Rows.Add(row)
            tb.LoadDataRow(New Object() _
            {101, "Kamala", 4500}, True)

            Dim buffer As System.Text.StringBuilder
            buffer = New System.Text.StringBuilder

            For Each dc As DataColumn In tb.Columns
                buffer.Append(String.Format("{0:15}", dc.ColumnName))
            Next
            buffer.Append(vbCrLf)

            For Each dr As DataRow In tb.Rows
                For Each dc As DataColumn In tb.Columns
                    buffer.Append(String.Format("{0:15}", dr(dc)))
                Next
                buffer.Append(vbCrLf)
            Next
            TextBox1.Text = buffer.ToString

    This is only with datatable and after with dataview u can continue

    Thank u
    Baba
    Please remember to click "Mark as Answer" on this post if it helped you.

    Tuesday, September 18, 2007 9:18 AM
  •  

    Hi,

     

    I advice this;

     

    Add a DataSet to your project. And add your tables and relations using the designer. Then use your typed dataset instead of base DataSet. (read about typed datasets for more information, the best oo db)

     

     

     

    Also for simple tables, I do this; (I make use of DataTable class)

    1. Add an XmlSchema to your projects. (extension is same as dataset (.xsd) ) (but this designer is different, DataSet is also an xml schema but with Microsoft namespace and entities, XmlSchema is generating world standard schema, you can even send your schema to other applications)

    2. Add element to your designer (which means table) and give a name like "Items"

    3. Edit Items entity and define your columns

    4. Add a class to your project name it like "Items" like below.

    Code Snippet

    public class Items : System.Data.DataTable

    {

    public Items() : base("Items")

    {

    string schema = ReadTextResource(this, "XmlSchema1.xsd");

    ReadXmlSchema(new System.IO.StringReader(schema));

    PrimaryKey = new System.Data.DataColumn[] { Columns["Id"] };

    }

     

    public static string ReadTextResource(object Class, string FileName)

    {

    string aName = Class.GetType().Assembly.GetName().Name;

    string rName = aName + "." + FileName;

    System.IO.StreamReader fileContent = new System.IO.StreamReader(Class.GetType().Assembly.GetManifestResourceStream(rName));

    return fileContent.ReadToEnd();

    }

     

    }

     

     

     

    This is also a convenient way, also in this table you can any datatype you want (binary collections, serialized objects) just you need to know how to define XmlSchema.

     

    If you wanna store shopping cart items for example you can place an object of Items class to session.

     

    Making use of visual designers is a good practice, since you can easily alter your structure with less human errors.

     

    Regards,

    Bora Inceler

    Wednesday, September 19, 2007 5:05 AM