none
sqlAdapter for c# RRS feed

  • Question

  • please guide me!!

    i am having text file with 'n' of tables with different range of fileds(columns). i have to read the text file and insert the data under each table.

    i finished first half.now i cant move to next step(inserting data in database table).

    each table have different no.of columns.i hope my task can be achieved through sqldata Adapater and sqlcommand builder. but i dont know how to use that!!

    i read data and have in one generic list. now i want to insert data to database table.

    problem i am facing was "how to write insert query for all table". can i write any common query for insertion!!

    please help me!!

    • Moved by CoolDadTx Friday, May 25, 2012 1:45 PM ADO.NET related (From:Visual C# General)
    Friday, May 25, 2012 1:32 PM

Answers

  • Inserting into a database is really a 2-step process. You can just generate a bunch of insert scripts yourself, but that is a pain. The better option is to pick a library to do it for you.

    First, you'll want to create the database itself (some libraries will auto-generate database tables for you, but I recommend always creating them yourself and knowing what is in there).

    Second, you can generate your client-side classes to match the table. If you're just writing a simple application and figuring out how things work, I'd recommend LINQ to SQL, since it's included in VS and is easy to set up. Create a new LINQ to SQL model and add your database tables to it.

    Next, you'll insert into the database using the DataContext class using auto-generated methods to insert into each table. See this article on CodePlex for a good example of how to use LINQ to SQL.


    Check out My Blog. Now updated to actually work!

    Friday, May 25, 2012 1:52 PM