[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?
Re: [2005] Setting table specs on a table I made in code
VB Code:
Dim dt As New DataTable
'Add two columns.
dt.Columns.Add("ID", GetType(Integer))
dt.Columns.Add("Name" GetType(String))
Dim dr As DataRow
'Add five rows.
For i As Integer = 1 To 5
dr = dt.NewRow()
dr("ID") = i
dr("Name") = "Name " & i
dt.Rows.Add(dr)
Next i