Hi Justin,
Here's a quick sample .aspx page that creates a dataset in code, adds a few
lines of data and persists the dataset to a file. When you click the button,
it loads the dataset from the file and displays it in the grid.
Let us know if this helps?
Ken
Microsoft MVP [ASP.NET]
<%@ Page Language="VB" %>
<%@ import namespace="system.data" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<script runat="server">
Protected Sub Page_Load _
(ByVal sender As Object, _
ByVal e As System.EventArgs)
' Create a datatable and populate it
If Not IsPostBack Then
Dim ds As Data.DataSet = _
New Data.DataSet()
Dim dt As New Data.DataTable
Dim dr As Data.DataRow
dt.Columns.Add(New Data.DataColumn _
("IntegerValue", GetType(Int32)))
dt.Columns.Add(New Data.DataColumn _
("StringValue", GetType(String)))
dt.Columns.Add(New Data.DataColumn _
("CurrencyValue", GetType(Double)))
dt.Columns.Add(New Data.DataColumn _
("Boolean", GetType(Boolean)))
Dim i As Integer
For i = 0 To 5
dr = dt.NewRow()
dr(0) = i
dr(1) = "Item " + i.ToString()
dr(2) = 1.23 * (i + 1)
dr(3) = (i = 4)
dt.Rows.Add(dr)
Next i
' Add the table to the dataset
ds.Tables.Add(dt)
' Write the dataset to a file
ds.WriteXml(Server.MapPath("app_data/ds.xsd"), _
Data.XmlWriteMode.WriteSchema)
End If
End Sub
Protected Sub Button1_Click _
(ByVal sender As Object, _
ByVal e As System.EventArgs)
' Create an empty dataset
Dim ds As New DataSet
' Read the dataset from the file
ds.ReadXml(Server.MapPath("app_data/ds.xsd"), _
XmlReadMode.ReadSchema)
' Bind to the Gridview
If Not IsNothing(ds) Then
GridView1.DataSource = ds
GridView1.DataBind()
End If
End Sub
</script>
<html xmlns="http://www.w3.org/1999/xhtml" >
<head runat="server">
<title>Create a DataSet in code and read it</title>
</head>
<body>
<form id="form1" runat="server">
<div>
DataSet sample by Ken Cox - Microsoft MVP [ASP.NET]<br />
<br />
<asp:gridview id="GridView1" runat="server">
</asp:gridview>
<br />
<asp:button id="Button1" runat="server"
onclick="Button1_Click" text="Use DataSet From File" /></div>
</form>
</body>
</html>
"Justin" <Ju****@NoSpam.comwrote in message
news:%2****************@TK2MSFTNGP06.phx.gbl...
I'm just learning ASP.NET 2.0 and everything I find on Datasets including
the MSPress book I bought go way to far for what I need. I do not need to
bind a datasource. My source will be a text file that I will read line
by line.
All I want to do is create a dataset and add records to it manualy that I
will read from a text file. To start I'm just trying to add a single
record. I then want to bind that dataset to a gridview.
To start is this correct for far:
Protected Sub Page_Load(ByVal sender As Object, ByVal e As EventArgs)
Dim ds As Data.DataSet = New Data.DataSet()
GridView1.DataSource = ds
GridView1.DataBind()
End Sub
How do I add records to it?
Thanks for any help