View Single Post
Old Sep 6th, 2005, 2:49 AM   #5
re10
Newbie
 
Join Date: Aug 2005
Posts: 10
Rep Power: 0 re10 is on a distinguished road
The codes (in code tags):

////Program to create table
namespace database1
{
using System;
using System.Data.ADO;

public class Class1
{
public Class1()
{
//
// TODO: Add Constructor Logic here
//
}

public static int Main(string[] args)
{
try
{
ADOConnection s = new ADOConnection("Data Source=mymdb");
s.Open();
Console.WriteLine("Connection established");

//Create the table
Console.Write("Do you want to create a table?(y/n) ");
string ch = Console.ReadLine();
if (ch == "y")
{
ADOCommand CreateTable = new ADOCommand("Create Table Table1(vno integer,name char(20))", s);
CreateTable.ExecuteNonQuery();
Console.WriteLine("ADOCommand executed / Table created");
}


//Insert values into the table
Console.Write("Do you want to insert some values in a table?(y/n) ");
ch = Console.ReadLine();
if (ch == "y")
{
ADOCommand InsTable = new
ADOCommand("insert into Table1 values(1, 'hi')", s);

InsTable.ExecuteNonQuery();
Console.WriteLine("Values inserted");
}

//Delete the whole table
Console.Write("Do you want to delete all records present in the table?(y/n) ");
ch = Console.ReadLine();
if (ch == "y")
{
ADOCommand DeleteTable = new ADOCommand("Delete from Table1", s);
DeleteTable.ExecuteNonQuery();
Console.WriteLine("All records deleted");
}

//View all records
Console.Write("Do you want to view all records present in the table (y/n)? ");
ch = Console.ReadLine();
if (ch == "y")
{
ADOCommand AllRecs = new ADOCommand("select * from Table1", s);
//AllRecs.ExecuteNonQuery();
ADODataReader r;
AllRecs.Execute(out r);
while (r.Read())
{
for (int i = 0; i < r.FieldCount; i++)
{
Console.Write(r.GetValue(i) + " ");
}
Console.WriteLine();
}
Console.WriteLine("All Records Displayed");
r.Close();
}

s.Close();
Console.ReadLine();

}
catch (System.Exception e)
{
Console.WriteLine(e.ToString());
Console.ReadLine();
}

return 0;
} // Main End
} // Class Ends
}// namespace ends
//End of program

Getting the following error:
The type or namespace name 'ADO' does not exist in the namespace 'System.Data' (are you missing an assembly reference?)C:\Documents and Settings\rm\Desktop\Program\test1\Program.cs
Line: 4
Column: 23
Project: database1

Thx for any help
re10 is offline   Reply With Quote