![]() |
|
![]() |
|
|
Thread Tools | Display Modes |
|
|
#1 |
|
Newbie
Join Date: Aug 2005
Posts: 10
Rep Power: 0
![]() |
program to create tables and queries
Hello,
Can anyone help me? I need to create a program in C# to automatically create tables/queries in MS Access (using ADO). Thx. |
|
|
|
|
|
#2 |
|
I eat cake for breakfast.
![]() ![]() ![]() ![]() Join Date: Jul 2004
Location: In my box.
Posts: 4,434
Rep Power: 8
![]() |
Yes. Write some code and I'll help you.
|
|
|
|
|
|
#3 |
|
Newbie
Join Date: Aug 2005
Posts: 10
Rep Power: 0
![]() |
type or namespace 'ADO' problem
Hi,
Here is how the codes look like: ////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 I'm 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 Pls help me to sort this out Thx in advance |
|
|
|
|
|
#4 |
|
Professional Programmer
|
Edit your post and put that in CODE tags.
__________________
% rc4 hexkey < input > output
#define S ,t=s[i],s[i]=s[j],s[j]=t /* rc4 hexkey <file */
unsigned char k[256],s[256],i,j,t;main(c,v,e)char**v;{++v;while(++i)s[
i]=i;for(c=0;*(*v)++;k[c++]=e)sscanf((*v)++-1,"%2x",&e);while(j+=s[i]
+k[i%c]S,++i);for(j=0;c=~getchar();putchar(~c^s[t+=s[i]]))j+=s[++i]S;} |
|
|
|
|
|
#5 |
|
Newbie
Join Date: Aug 2005
Posts: 10
Rep Power: 0
![]() |
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 programGetting 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 |
|
|
|
|
|
#6 |
|
Programming Guru
![]() ![]() ![]() |
Sounds like you need to add a reference to ADO in your project.
__________________
http://jasonpowers.net "There are a thousand hacking at the branches of evil to one who is striking at the root." |
|
|
|
![]() |
| Bookmarks |
| Currently Active Users Viewing This Thread: 1 (0 members and 1 guests) | |
| Thread Tools | |
| Display Modes | |
|
|