Results 1 to 6 of 6

Thread: Sql with Visual C++ or Visual basic kindly help

  1. #1

    Thread Starter
    New Member
    Join Date
    Feb 2011
    Posts
    4

    Sql with Visual C++ or Visual basic kindly help

    Take user input n as an integer

    If user inputs n= 3 The I should create a table with 3 fields say d1 d2 d3

    If user inputs n=4 The I should create a table with 4 fields say d1 d2 d3 d4

    If user inputs n=5 The I should create a table with 5 fields say d1 d2 d3 d4 d5

  2. #2
    Frenzied Member
    Join Date
    May 2006
    Location
    some place in the cloud
    Posts
    1,886

    Re: Sql with Visual C++ or Visual basic kindly help

    The SQL syntax for CREATE TABLE is

    CREATE TABLE "table_name" ("column 1" "data_type_for_column_1",
    "column 2" "data_type_for_column_2",
    ... )

    You should google for the way to execute this statement using the prog language and the data access that You are using or want to use

    JG

  3. #3

    Thread Starter
    New Member
    Join Date
    Feb 2011
    Posts
    4

    Re: Sql with Visual C++ or Visual basic kindly help

    How to change the number of column's dynamically on each execution of procedure based on the value of n.

  4. #4
    Frenzied Member
    Join Date
    May 2006
    Location
    some place in the cloud
    Posts
    1,886

    Re: Sql with Visual C++ or Visual basic kindly help

    Something like this...
    Code:
    Dim MyStr As String
    
    MyStr = "CREATE TABLE [dbo].[tablename] (" 
    
    Select Case n
        Case 1
            MyStr = MyStr & "[fieldname1]	[datatype] (lenght)"
        Case 2
            MyStr = MyStr & ",[fieldname2]	[datatype] (lenght)"
        Case 3
            MyStr = MyStr & ",[fieldname3]  [datatype] (lenght)"
    'and so on
    End Select
    
    MyStr = MyStr & ")"
    
    MsgBox MyStr
    JG

  5. #5

    Thread Starter
    New Member
    Join Date
    Feb 2011
    Posts
    4

    Re: Sql with Visual C++ or Visual basic kindly help

    The is OK only if we know what values are permmisble for n say only 1,2,3 or 100

    But if the user types n=100 it should create table with field names
    d1,d2,d3,....,d100 all varchar



    n=101 it should create table with field names
    d1,d2,d3,....,d100,d101 all varchar

    etc.

  6. #6
    Frenzied Member
    Join Date
    May 2006
    Location
    some place in the cloud
    Posts
    1,886

    Re: Sql with Visual C++ or Visual basic kindly help

    Then You could try a Do-Loop or a For-Next iteration

    JG

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width