Results 1 to 2 of 2

Thread: [2005] Setting table specs on a table I made in code

  1. #1

    Thread Starter
    Hyperactive Member
    Join Date
    Oct 2005
    Posts
    257

    [2005] Setting table specs on a table I made in code

    I want to create a datatable to hold test results from a testing program and I'm adding rows like this:

    Dim NewRow As DataRow
    NewRow = tblUserAnswers.Rows.Add
    NewRow.Item(0) = m_intUserId
    etc

    which I'm not exactly sure is going to work anyway but how do I set the number of columns and their datatypes to match the Results table in the actual database so that I can send it to the database later (btw is there even a way to do that?) and it won't give me a bunch of datatype mismatch errors or number of columns errors or something. Or do I even have to do that at all?
    I tried to end process on Visual Studio 2005
    but PETA stopped me saying it's smart enough
    to be a living creature

  2. #2
    Super Moderator jmcilhinney's Avatar
    Join Date
    May 2005
    Location
    Sydney, Australia
    Posts
    111,221

    Re: [2005] Setting table specs on a table I made in code

    VB Code:
    1. Dim dt As New DataTable
    2.  
    3. 'Add two columns.
    4. dt.Columns.Add("ID", GetType(Integer))
    5. dt.Columns.Add("Name" GetType(String))
    6.  
    7. Dim dr As DataRow
    8.  
    9. 'Add five rows.
    10. For i As Integer = 1 To 5
    11.     dr = dt.NewRow()
    12.     dr("ID") = i
    13.     dr("Name") = "Name " & i
    14.     dt.Rows.Add(dr)
    15. Next i
    Why is my data not saved to my database? | MSDN Data Walkthroughs
    VBForums Database Development FAQ
    My CodeBank Submissions: VB | C#
    My Blog: Data Among Multiple Forms (3 parts)
    Beginner Tutorials: VB | C# | SQL

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