millerje
asked on
C# how to write to DataTable
I have created a DataSet and a DataTable inside my C# application so I can create a report. I do not have a SQL database or an Access database. I want to know how to pass the information from a text box and/or list box to the DataTable that is inside my application.
SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
using System;
using System.Data;
class Program
{
static void Main()
{
// Create two DataTable instances.
DataTable table1 = new DataTable("patients");
table1.Columns.Add("name") ;
table1.Columns.Add("id");
table1.Rows.Add("sam", 1);
table1.Rows.Add("mark", 2);
DataTable table2 = new DataTable("medications");
table2.Columns.Add("id");
table2.Columns.Add("medica tion");
table2.Rows.Add(1, "atenolol");
table2.Rows.Add(2, "amoxicillin");
// Create a DataSet and put both tables in it.
DataSet set = new DataSet("office");
set.Tables.Add(table1);
set.Tables.Add(table2);
// Visualize DataSet.
Console.WriteLine(set.GetX ml());
}
}
using System.Data;
class Program
{
static void Main()
{
// Create two DataTable instances.
DataTable table1 = new DataTable("patients");
table1.Columns.Add("name")
table1.Columns.Add("id");
table1.Rows.Add("sam", 1);
table1.Rows.Add("mark", 2);
DataTable table2 = new DataTable("medications");
table2.Columns.Add("id");
table2.Columns.Add("medica
table2.Rows.Add(1, "atenolol");
table2.Rows.Add(2, "amoxicillin");
// Create a DataSet and put both tables in it.
DataSet set = new DataSet("office");
set.Tables.Add(table1);
set.Tables.Add(table2);
// Visualize DataSet.
Console.WriteLine(set.GetX
}
}
if you want to store data whatever added in data table(s) use this code
//it will write xml file
set.WriteXml("filename.xml ");
//it will read xml file
ds.ReadXml("filename.xml") ;
rebind the dataset once you read xml file, so you can load saved data.
//it will write xml file
set.WriteXml("filename.xml
//it will read xml file
ds.ReadXml("filename.xml")
rebind the dataset once you read xml file, so you can load saved data.
ASKER
I think all the above information is good. I want to make sure my original question was clear though. In my project I have added a new item and selected "dataset" and named it DataSet_SysInfo.xsd. In the dataset design view I created a "DataTable" and named it AssetInfo and added columns to it. I have then designed my report.rdlc to point to that datatable. So on my report form, in the report viewer I pointed it to report.rdlc. So how to I add information to the datatable I have alread created in design view?
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
http://social.msdn.microsoft.com/Forums/is/csharpgeneral/thread/07d8321a-4b54-49b3-9bfe-94269affade8
http://forums.aspfree.com/net-development-11/populate-listbox-data-table-154979.html
http://forums.asp.net/t/861074.aspx/1