2 Replies - 2064 Views - Last Post: 04 March 2013 - 12:50 PM Rate Topic: -----

#1 parry2411  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 49
  • Joined: 13-February 13

Dynamically Creating SQL Tables In A Database (Adding Primary Keys)

Posted 04 March 2013 - 03:35 AM

Im trying to develop a program which allows you to dynamically add tables to An SQL database, WHile the program is running you have to:

  • Has To Enter The Table Name
  • Then Add Asmany Column Names and their datatypes


When they have entreered all the column details they are prompted to add a primary keys and Froegen Keys.

Im having trouble on the Adding primary keys, This what i have done so far:

The user inouts the primary keys and they are seperated using commas.

In the code area i have:

>Getting The Values From The User

>Entering The Values To A string Varaible Called pKeys. using readline()

Now seperating the values from the commas to get the entered numbers

IList<string> primaryKeyValues = pKeys.Split(new string[] { ",", " " },
StringSplitOptions.RemoveEmptyEntries);


Then i convert the strings into Integer values so i can use these as index accessors to the array i have holding the tableColum details

int[] primaryKeyIntValues = new int[primaryKeyValues.Count];
               
 int counter = 0;
                
foreach (string s in primaryKeyValues)
{
     primaryKeyIntValues[counter++] = int.Parse(s);
}


I have a database connection program implemented which has a update method and this is the parameter i pass on:

DatbaseConn.Update("CREATE TABLE " + tableName + "(" + tableColumnsJoined + ", PRIMARY KEY(" ")");


Im not shure how can i access the colums to craete a primary keys in this sentence of code abovce.

Would anyone have any advice.

Thanks

Is This A Good Question/Topic? 0
  • +

Replies To: Dynamically Creating SQL Tables In A Database (Adding Primary Keys)

#2 Skydiver  Icon User is offline

  • Code herder
  • member icon

Reputation: 3662
  • View blog
  • Posts: 11,473
  • Joined: 05-May 12

Re: Dynamically Creating SQL Tables In A Database (Adding Primary Keys)

Posted 04 March 2013 - 07:03 AM

This looks more like a SQL problem rather than a C# problem. It's not that you are having a problem writing C# code, but a problem of writing SQL code. Moving...
Was This Post Helpful? 0
  • +
  • -

#3 parry2411  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 49
  • Joined: 13-February 13

Re: Dynamically Creating SQL Tables In A Database (Adding Primary Keys)

Posted 04 March 2013 - 12:50 PM

I know that the SQL is incorrect, But commenting the SQL stataements out brings up a run time error, Something about the loop taking in zero or non values
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1