Click here to Skip to main content
15,912,756 members
Home / Discussions / C#
   

C#

 
GeneralRe: Video editing Pin
sana1715-Oct-08 8:49
sana1715-Oct-08 8:49 
Questionsave to the database.please help.sos with the code. Pin
sakis2415-Oct-08 6:40
sakis2415-Oct-08 6:40 
AnswerRe: save to the database.please help.sos with the code. Pin
Dave Kreskowiak15-Oct-08 7:49
mveDave Kreskowiak15-Oct-08 7:49 
GeneralRe: save to the database.please help.sos with the code. Pin
sakis2416-Oct-08 8:45
sakis2416-Oct-08 8:45 
Questiondithering Pin
afjepoifesahie15-Oct-08 6:38
afjepoifesahie15-Oct-08 6:38 
AnswerRe: dithering Pin
Dave Kreskowiak15-Oct-08 7:45
mveDave Kreskowiak15-Oct-08 7:45 
GeneralRe: dithering Pin
Anthony Mushrow15-Oct-08 7:50
professionalAnthony Mushrow15-Oct-08 7:50 
QuestionCheck for Table and Create Table if it is not found Pin
Planker15-Oct-08 5:43
Planker15-Oct-08 5:43 
I'm needing a little help figuring out the best way to check if a table exist in an access DB and then set a flag to create the Table. I want to set this up with reusable code.

right now i am setting the commandtext with the SQL query that I want to convert to varaibles but want to figure out how I want to do this first because it is most likely part of the overall solution for this.

I'm opening the Database reading the GetSchema and reading each table name and have an array of my tables that the program is going to create, I can compare these but I'm getting lost on how to keep three array's in sync with out putting in individual checks for each table. yes the code below only has 5 tables but this application is going to grow in future versions and i don't want to have to go back and recode this or add checks for each table.

// array of tables that will be created
           string[] NATables = new string[5];
           NATables[0] = "Group Policy";
           NATables[1] = "GPO Computer Settings";
           NATables[2] = "GPO User Settings";
           NATables[3] = "GPO Links";
           NATables[4] = "GPO Delegation";


           String connect = "Provider=Microsoft.JET.OLEDB.4.0;data source=.\\Test.mdb";
           OleDbConnection con = new OleDbConnection(connect);
           con.Open();
           OleDbCommand cmd = con.CreateCommand();

           //check for tables before creating

           //Get Tables from Database
           DataTable dt = con.GetSchema("tables");
           //close Connection to database
           con.Close();
           // get all rows from the table
           DataRow[] rows = dt.Select();
           // loop through the records searching for tables and set flag for tables that need to be created
           for (int i =0; i < rows.Length; i++ )
           {
               string r = rows[i]["TABLE_NAME"].ToString();
               for (int j = 0; j < NATables.Length; j++)
               {
                   if (r == NATables[j])
                   {
                       //don't create table
                   }
                   else
                   {
                       //set create table flag
                   }
               }
           }
           // Run SQL commands to create tables
           con.Open();
           cmd.CommandText = "CREATE TABLE [Group Policy]([GPO GUID] Text(50) NOT NULL Unique PRIMARY KEY,[GPO NAME] TEXT(50) NOT NULL,[GPO Domain] TEXT(50) NOT NULL,Created datetime NOT NULL,Modified datetime NOT NULL,Status TEXT(10) NOT NULL)";
           try
           {
               cmd.ExecuteNonQuery();
           }
           catch (Exception ex)
           {
               MessageBox.Show(ex.ToString());
           }

AnswerRe: Check for Table and Create Table if it is not found Pin
Wendelius15-Oct-08 7:52
mentorWendelius15-Oct-08 7:52 
GeneralRe: Check for Table and Create Table if it is not found Pin
Planker15-Oct-08 8:17
Planker15-Oct-08 8:17 
GeneralRe: Check for Table and Create Table if it is not found Pin
Wendelius15-Oct-08 8:23
mentorWendelius15-Oct-08 8:23 
QuestionC# Code Help Pin
boiDev15-Oct-08 5:30
boiDev15-Oct-08 5:30 
AnswerRe: C# Code Help Pin
Pedram Behroozi15-Oct-08 5:54
Pedram Behroozi15-Oct-08 5:54 
GeneralRe: C# Code Help Pin
boiDev15-Oct-08 6:57
boiDev15-Oct-08 6:57 
AnswerLET ME DROP EVERYTHING AND WORK ON YOUR PROBLEM Pin
Le centriste15-Oct-08 6:26
Le centriste15-Oct-08 6:26 
GeneralRe: LET ME DROP EVERYTHING AND WORK ON YOUR PROBLEM Pin
boiDev15-Oct-08 6:28
boiDev15-Oct-08 6:28 
GeneralRe: LET ME DROP EVERYTHING AND WORK ON YOUR PROBLEM Pin
Le centriste15-Oct-08 6:29
Le centriste15-Oct-08 6:29 
GeneralRe: LET ME DROP EVERYTHING AND WORK ON YOUR PROBLEM Pin
boiDev15-Oct-08 6:50
boiDev15-Oct-08 6:50 
JokeRe: C# Code Help Pin
nelsonpaixao15-Oct-08 14:00
nelsonpaixao15-Oct-08 14:00 
AnswerRe: C# Code Help Pin
Lea Hayes17-Oct-08 4:32
Lea Hayes17-Oct-08 4:32 
GeneralRe: C# Code Help Pin
boiDev17-Oct-08 5:14
boiDev17-Oct-08 5:14 
QuestionC# Help Urgent Pin
boiDev15-Oct-08 5:13
boiDev15-Oct-08 5:13 
AnswerRe: C# Help Urgent - OH NO ITS NOT!!!!!!!!!!!!!!! Pin
Ashfield15-Oct-08 5:17
Ashfield15-Oct-08 5:17 
GeneralRe: C# Help Urgent - OH NO ITS NOT!!!!!!!!!!!!!!! Pin
boiDev15-Oct-08 5:19
boiDev15-Oct-08 5:19 
GeneralRe: C# Help Urgent - OH NO ITS NOT!!!!!!!!!!!!!!! Pin
J4amieC15-Oct-08 5:50
J4amieC15-Oct-08 5:50 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.