How to Display Data in a List View from an inner join query

EDN Admin

Well-known member
Joined
Aug 7, 2010
Messages
12,794
Location
In the Machine
My current query is not working-does anyone have any insight on what could be the error(S)?
note: the parameter control references another form,hence, the prefix frm4-
Any help will be appreciated.
thanks. Me.lstNote.View = View.Details
Me.lstNote.GridLines = True

dbProvider = "Provider=Microsoft.SQLSERVER.CE.OLEDB.3.5;"
dbSource = "Data Source=C:UsersCoreDesktopDatabasesMyDatabase#1.sdf"
con.ConnectionString = dbProvider & dbSource

Dim strSql1 As String
Try

Dim sql = "SELECT todoListID,taskStatus, taskETCID FROM ToDoList INNER JOIN StickyNote ON ToDoList.stickyNoteID = StickyNote.noteID WHERE (noteDate = @date)"

Using cn As New SqlConnection(dbSource), cmd As New SqlCommand(sql, cn)

cn.Open()

cmd.Parameters.Add("@date", SqlDbType.DateTime).Value = frm4.dtpCalendarNote.Value.ToShortDateString

da = New OleDb.OleDbDataAdapter(sql, con)
ds = New DataSet
da.Fill(ds, "TaskNote")

Dim i As Integer = 0
Dim j As Integer = 0
For i = 0 To ds.Tables(0).Columns.Count - 1
Me.lstNote.Columns.Add(ds.Tables(0).Columns(i).ColumnName.ToString())
Next

For i = 0 To ds.Tables(0).Rows.Count - 1
For j = 0 To ds.Tables(0).Columns.Count - 1
itemcoll(j) = ds.Tables(0).Rows(i)(j).ToString()
Next
Dim lvi As New ListViewItem(itemcoll)
Me.lstNote.Items.Add(lvi)
Me.lstNote.AutoResizeColumns(ColumnHeaderAutoResizeStyle.ColumnContent)

Next
End Using

OTC(One Tooth Coder)

View the full article
 
Back
Top