Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. Database & SysAdmin
  3. Database
  4. Order of procedures to add a table

Order of procedures to add a table

Scheduled Pinned Locked Moved Database
databasejsonhelp
1 Posts 1 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • T Offline
    T Offline
    thecodedemon
    wrote on last edited by
    #1

    So, I've got an open connection to my DB, I've got a dataSet, I've made my table and added it to the dataSet, I've got a SqlDataAdapter, constructed with a SELECT command string. I would like to use the SqlCommandBuilder to get the rest of the SQL commands in the DataAdapter, but I can't seem to find the correct order to do everything. I need to add the table to the dataset, initialize the adapter for the table, build the other commands for the adapter, and finally save everything back to the DB on disk. Below is my code, and I'm sure hoping someone can point me in the right direction. I know it seems long, but there are lots of comments and extra lines. I really need help on this, been working all hours for 2 days trying to figure this out. private void CheckDDBTables() { DataTable table; DataColumn column; DirectoryInfo dir = new DirectoryInfo( Application.StartupPath + "\\forms\\" ); bool needNewtable = true; CustomFormat frm = new CustomFormat(); SqlDataAdapter tempDA; SqlCommandBuilder builder; string selStr = ""; // SELECT "column_name" FROM "table_name" DBConn.Open(); // a global SqlConnection, intialized with the correct connection string // loop through all files in the directory foreach( FileInfo fli in dir.GetFiles( "*.*" ) ) { // for every form file, make a table, to make the DataAdapter // load the file into the form, function also inits LoadFile( "\\forms\\" + fli.Name, out frm ); // init the selStr selStr = "SELECT "; // make a new table for this file table = new DataTable( frm.name.Substring( 0, frm.name.Length - 4 ) ); // identity index column column = new DataColumn( "Listing", typeof( int ) ); column.AllowDBNull = false; column.AutoIncrement = true; column.Unique = true; column.AutoIncrementSeed = 1000; table.Columns.Add( column ); table.PrimaryKey = new DataColumn[] { table.Columns[ 0 ] }; // add column to selStr selStr += column.ColumnName + ","; // begin adding columns, for each item in frm foreach( Item gc in frm.ItemList ) { // new column column = new DataColumn( gc.name, typeof( string ) ); // add the column to the table table.Columns.Add( column ); // add column to selStr selStr += column.ColumnName + ","; } // en

    1 Reply Last reply
    0
    Reply
    • Reply as topic
    Log in to reply
    • Oldest to Newest
    • Newest to Oldest
    • Most Votes


    • Login

    • Don't have an account? Register

    • Login or register to search.
    • First post
      Last post
    0
    • Categories
    • Recent
    • Tags
    • Popular
    • World
    • Users
    • Groups