Programming Forums
User Name Password Register
 

RSS Feed
FORUM INDEX | TODAY'S POSTS | UNANSWERED THREADS | ADVANCED SEARCH

Reply
 
Thread Tools Display Modes
Old Sep 5th, 2005, 3:16 AM   #1
re10
Newbie
 
Join Date: Aug 2005
Posts: 10
Rep Power: 0 re10 is on a distinguished road
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.
re10 is offline   Reply With Quote
Old Sep 5th, 2005, 9:49 AM   #2
Ooble
I eat cake for breakfast.
 
Ooble's Avatar
 
Join Date: Jul 2004
Location: In my box.
Posts: 4,434
Rep Power: 8 Ooble is on a distinguished road
Yes. Write some code and I'll help you.
__________________
Me :: You :: Them
Ooble is offline   Reply With Quote
Old Sep 6th, 2005, 12:26 AM   #3
re10
Newbie
 
Join Date: Aug 2005
Posts: 10
Rep Power: 0 re10 is on a distinguished road
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
re10 is offline   Reply With Quote
Old Sep 6th, 2005, 1:33 AM   #4
iignotus
Professional Programmer
 
iignotus's Avatar
 
Join Date: Apr 2005
Location: Nowhere Special
Posts: 466
Rep Power: 4 iignotus is on a distinguished road
Send a message via AIM to iignotus
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;}
iignotus is offline   Reply With Quote
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
Old Sep 6th, 2005, 8:47 AM   #6
Infinite Recursion
Programming Guru
 
Infinite Recursion's Avatar
 
Join Date: Jul 2004
Location: United States
Posts: 3,453
Rep Power: 7 Infinite Recursion is on a distinguished road
Send a message via MSN to Infinite Recursion Send a message via Yahoo to Infinite Recursion
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."
Infinite Recursion is offline   Reply With Quote
Reply

Bookmarks

« Previous Thread in Forum | Next Thread in Forum »

Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Forum Jump




DaniWeb IT Discussion Community
All times are GMT -5. The time now is 4:19 AM.

Powered by vBulletin® Version 3.7.0, Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Copyright ©2007 DaniWeb® LLC