[RESOLVED] Column pulling of a database
CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 6 of 6

Thread: [RESOLVED] Column pulling of a database

  1. #1
    Join Date
    Apr 2013
    Location
    USA
    Posts
    6

    [RESOLVED] Column pulling of a database

    Ok. I've been working on this project for a while and I've looked everywhere from stackoverflow to MSDN for a way to pull columns from a database. I want to format each column to a prefixed length. Any way that I can be able to call the columns of a DataTable to a individual variables as to call them by their variable name? If so, how would this be done? I'm completely new and I've been learning C# on my own. Please help???? Here is relevant code:

    string query = "SELECT * FROM CJIS_JAIL_PARTIES";
    SqlConnection connString = new SqlConnection(connectionString);
    //Run query
    SqlCommand execution = new SqlCommand(query, connString);
    //Execute the SQL DataReader
    SqlDataReader executionReader = execution.ExecuteReader();
    //Create DataTable to hold data returned from query
    DataTable dataTable = new DataTable();
    //Create DataTable.Load(SqlDataReader) to put the results of the query into a DataTable
    dataTable.Load(executionReader);

  2. #2
    Join Date
    Jan 2006
    Location
    Chicago, IL
    Posts
    14,959

    Re: Column pulling of a database

    Save it, or export/import it is one way
    David

    CodeGuru Article: Bound Controls are Evil-VB6
    2013 Samples: MS CODE Samples

    CodeGuru Reviewer
    2006 Dell CSP
    2006, 2007 & 2008 MVP Visual Basic
    If your question has been answered satisfactorily, and it has been helpful, then, please, Rate this Post!

  3. #3
    Join Date
    Apr 2013
    Location
    USA
    Posts
    6

    Re: Column pulling of a database

    Quote Originally Posted by dglienna View Post
    Save it, or export/import it is one way
    I'm not looking to export/import because I'm trying to write it to a preformatted file.

  4. #4
    Join Date
    Jan 2006
    Location
    Chicago, IL
    Posts
    14,959

    Re: Column pulling of a database

    What format is returned? Probably loses the formatting...
    David

    CodeGuru Article: Bound Controls are Evil-VB6
    2013 Samples: MS CODE Samples

    CodeGuru Reviewer
    2006 Dell CSP
    2006, 2007 & 2008 MVP Visual Basic
    If your question has been answered satisfactorily, and it has been helpful, then, please, Rate this Post!

  5. #5
    Join Date
    Sep 2000
    Location
    FL
    Posts
    1,451

    Re: Column pulling of a database

    What do you do with the datatable? Does it have to be in a data table? If not, create an entity class that mimics the database table, and use a reader to populate the class. Create a collection, or list of your entity class for the rows. Then you can call the variables anything you want.

  6. #6
    Join Date
    Apr 2013
    Location
    USA
    Posts
    6

    Re: Column pulling of a database

    Thank you. That helps a lot I'm know most basic and some advanced stuff. This is what I was looking for. Thank you

Tags for this Thread

Posting Permissions

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


Azure Activities Information Page

Windows Mobile Development Center


Click Here to Expand Forum to Full Width

This is a CodeGuru survey question.


Featured


HTML5 Development Center