X
Xarky
Hi,
I am trying to write a program, where I want to fill some records,
write them to a file and then display them back to screen.
What I have done is the following, but it is giving me an error during
execution.
/*********************************************/
using System;
using System.Data;
using System.IO;
namespace DBTesting
{
public class DBObject : DataSet // important for tables
{
// database tables
public const string TABLE_NAME = "Clubs";
// database fields
public const string CLUB_NAME = "Club Name";
public const string LEAGUES_WON = "Leagues Won";
public DBObject()
{
createTables();
} // end constructor
private void createTables()
{
// created the table
this.Tables.Add(new DataTable(TABLE_NAME));
// creating the field names
this.Tables[TABLE_NAME].Columns.Add(CLUB_NAME,
typeof(System.Byte[]));
this.Tables[TABLE_NAME].Columns.Add(LEAGUES_WON, typeof(Int32));
} // end method createTables
} // end class DBObject
} // end namespace DBTesting
namespace DBTesting
{
class Class1
{
[STAThread]
static void Main(string[] args)
{
// Instance of the database
DBObject db = new DBObject();
// Creating a row in the database
DataRow dr = db.Tables[DBObject.TABLE_NAME].NewRow();
// Filling the data in the row just created
dr[DBObject.CLUB_NAME] = "Milan";
dr[DBObject.LEAGUES_WON] = 17;
// Writing the row just filled to the database
db.Tables[DBObject.TABLE_NAME].Rows.Add(dr);
db.WriteXml(@"c:\test.xml");
Console.WriteLine ("Testing the program");
Console.WriteLine ("Record 1 : {0}", db.ReadXml(@"c:\test.xml"));
Console.ReadLine();
} // end Main method
} // end Class1
} // end namespace DBTesting
/******************************************/
This is only a test program, for me to learn how to program databases.
Can someone figure my problem out.
Thanks in Advance
I am trying to write a program, where I want to fill some records,
write them to a file and then display them back to screen.
What I have done is the following, but it is giving me an error during
execution.
/*********************************************/
using System;
using System.Data;
using System.IO;
namespace DBTesting
{
public class DBObject : DataSet // important for tables
{
// database tables
public const string TABLE_NAME = "Clubs";
// database fields
public const string CLUB_NAME = "Club Name";
public const string LEAGUES_WON = "Leagues Won";
public DBObject()
{
createTables();
} // end constructor
private void createTables()
{
// created the table
this.Tables.Add(new DataTable(TABLE_NAME));
// creating the field names
this.Tables[TABLE_NAME].Columns.Add(CLUB_NAME,
typeof(System.Byte[]));
this.Tables[TABLE_NAME].Columns.Add(LEAGUES_WON, typeof(Int32));
} // end method createTables
} // end class DBObject
} // end namespace DBTesting
namespace DBTesting
{
class Class1
{
[STAThread]
static void Main(string[] args)
{
// Instance of the database
DBObject db = new DBObject();
// Creating a row in the database
DataRow dr = db.Tables[DBObject.TABLE_NAME].NewRow();
// Filling the data in the row just created
dr[DBObject.CLUB_NAME] = "Milan";
dr[DBObject.LEAGUES_WON] = 17;
// Writing the row just filled to the database
db.Tables[DBObject.TABLE_NAME].Rows.Add(dr);
db.WriteXml(@"c:\test.xml");
Console.WriteLine ("Testing the program");
Console.WriteLine ("Record 1 : {0}", db.ReadXml(@"c:\test.xml"));
Console.ReadLine();
} // end Main method
} // end Class1
} // end namespace DBTesting
/******************************************/
This is only a test program, for me to learn how to program databases.
Can someone figure my problem out.
Thanks in Advance