I can't think of a way to get rows out of a table.
It was easy doing it with VB.Net and I'm just finding vc++ really difficult.
This is what I have so far.
I've connected to the database file and I am able to get the data shown onto the datagrid.
SQLiteConnection^ ObjConnection = gcnew SQLiteConnection("Data Source=SwiftService.db3;");
SQLiteCommand^ ObjCommand = gcnew SQLiteCommand("SELECT * FROM Contact", ObjConnection);
ObjCommand->CommandType = CommandType::Text;
SQLiteDataAdapter^ ObjDataAdapter = gcnew SQLiteDataAdapter(ObjCommand);
DataSet^ dataSet = gcnew DataSet();
ObjDataAdapter->Fill(dataSet, "Contact");
DataTable table = gcnew DataTable("Contact");
dataGridView1->DataSource = dataSet->Tables["Contact"];
Instead of showing the data in the datagrid, I want to do a for each statement, which creates a panel with some labels inside it for each row in the table.
I've done something like this in VB.Net, which is shown below.
Private Sub CheckStockLevel_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
conn = GetConnect()
conn.Open()
Try
'Select statement
Dim comm As New SqlCommand("SELECT * FROM Part", conn)
Dim myReader As SqlDataReader = comm.ExecuteReader 'create datareader and execute sql statement
Dim dt As New DataTable() 'create a Data Table
dt.Load(myReader) 'Load the data into the data table
Dim lblArray As Label() = New Label(10) {} 'create an array of labels
Dim nRow As DataRow
Dim y As Integer = 0 'value of the label y-position
Dim no As Integer = 1 'value of the "number" label
Dim total As Integer = 0
Dim nfont As New Font("Microsoft Sans Serif", 12, FontStyle.Regular) 'label font
'Loop through each row in the datatable
For Each nRow In dt.Rows
Dim i As Integer = 0
'Loop through each array in the label array and set the properties
For i = 0 To UBound(lblArray)
lblArray(i) = New Label
lblArray(i).AutoSize = True
lblArray(i).BackColor = System.Drawing.Color.Transparent
lblArray(i).Font = nfont
Panel1.AutoScroll = True
'Me.Controls.Add(lblArray(i))
Me.Panel1.Controls.Add(lblArray(i))
Next
'set the label properties
lblArray(0).Text = no
lblArray(1).Text = nRow.Item(0).ToString()
lblArray(2).Text = nRow.Item(1).ToString()
lblArray(3).Text = nRow.Item(2).ToString()
lblArray(4).Text = nRow.Item(3).ToString()
lblArray(5).Text = nRow.Item(4).ToString()
lblArray(6).Text = nRow.Item(5).ToString()
lblArray(7).Text = nRow.Item(7).ToString()
lblArray(8).Text = nRow.Item(6).ToString()
lblArray(9).Text = nRow.Item(8).ToString()
lblArray(0).Location = New System.Drawing.Point(5, y)
lblArray(1).Location = New System.Drawing.Point(33, y)
lblArray(2).Location = New System.Drawing.Point(126, y)
lblArray(3).Location = New System.Drawing.Point(242, y)
lblArray(4).Location = New System.Drawing.Point(323, y)
lblArray(5).Location = New System.Drawing.Point(457, y)
lblArray(6).Location = New System.Drawing.Point(531, y)
lblArray(7).Location = New System.Drawing.Point(670, y)
lblArray(8).Location = New System.Drawing.Point(750, y)
lblArray(9).Location = New System.Drawing.Point(855, y)
total += nRow.Item(7)
no += 1
y = y + 30
Next
lblTotal.Text = total 'total stock label
lblParts.Text = dt.Rows.Count 'total parts label
Catch ex As Exception
MessageBox.Show("No records found", "Search")
MessageBox.Show(ex.ToString)
End Try
conn.Close()
End Sub
Thanks