1. Anuncie Aqui ! Entre em contato fdantas@4each.com.br

[SQL] Creating SQL table using C#

Discussão em 'Outras Linguagens' iniciado por Stack, Outubro 3, 2024 às 11:02.

  1. Stack

    Stack Membro Participativo

    I would like to create two SQL tables using C#, within a loop. Each table is different, and has its column names stored in an array. Each array of column names is actually obtained from the header of a csv file.

    ### fnames is an array of file paths (2 csv files)
    foreach string f in fnames)
    {
    ## snip
    using (StreamReader rdr = new StreamReader(f))
    {
    string header = read.line(); ## This is the array of table columns
    }
    string tab = Path.GetFileNameWithoutExtension(f);
    string query = @"create table "+ tab + ..."; #I am not sure how to write the column names and types dynamically
    }


    Imagine that:

    • The columns for table 1 are : Date (datetime), Value (int)
    • The columns for table 2 are : Date (datetime), ID (varchar(255)), Return (int)

    Note that the two tables have different columns with different types. How can I achieve this?

    Continue reading...

Compartilhe esta Página