items in listview load not showing - vb.net

i have a problem in viewing items in listview
this is my code
rs.Open("select tableStudentRecords.*, tableTransaction.*, tablePayments.* from tableStudentRecords, tableTransaction , tablePayments" & _
" where tableStudentRecords.studnum = tableTransaction.studnum and tablePayments.psitscode = tableTransaction.psitscode", con, 3, 3)
Dim i As Integer = 0
With lvPaymentRecords
Do Until rec.EOF
.Items.Add(rec("tableTransaction.studnum").Value)
x = rec("sname").Value & ", " & rec("fname").Value & " " & rec("mi").Value & " " & rec("ext").Value
.Items(i).SubItems.Add(x)
lvPaymentRecords.Items(i).SubItems.Add(rec("sem").Value)
.Items(i).SubItems.Add(rec("sy").Value)
.Items(i).SubItems.Add(rec("total").Value)
i = i + 1
rec.MoveNext()
Loop
End With
rec.Close()
con.Close()
the thing is, items wont appear in listview, i dont know what is the cause,
tableStudentRecords and tablePayments are both PRIMARY keys,
here is the database relationships
(im sorry i cant post the image due to less reputation)
tableStudentRecords _____ tableTransaction _____ tablePAyments
-studnum _____________ -psitscode _____________-psitscode
-sname _______________ -studnum ____________-sem
-fname ________________ -sy __________________-payname
-gndr __________________-total _______________-amount
i only need to view the sem from tablePayments in listview load,

You must declare a ListViewItem variable. The codes should be
Dim lpRec As ListViewItem
With lvPaymentRecords
Do Until rec.EOF
lpRec=.Items.Add(rec("tableTransaction.studnum").Value)
x = rec("sname").Value & ", " & rec("fname").Value & " " & rec("mi").Value & " " & rec("ext").Value
lpRec.SubItems.Add(x)
lpRec.SubItems.Add(rec("sem").Value)
lpRec.Items(i).SubItems.Add(rec("sy").Value)
lpRec.Items(i).SubItems.Add(rec("total").Value)
i = i + 1
rec.MoveNext()
Loop
End With
rec.Close()
con.Close()
Hope it can help you.

Related

How to fix this logical error about listbox

I'd like to create a list box in vb.net that lists the item whenever the user clicks the button it updates information, my variables are a string and an integer concatenated, the problem is that when the user clicks on the button the item doesn't remove on the list
I've tried converting the integer variable to string and it still doesn't work
Private Sub btnAddChicken_Click(sender As Object, e As EventArgs) Handles btnAddChicken.Click
If cmbChicken.SelectedIndex = 0 Then
'''qfried is the quantity
'''tfried is the total amount
'''tfried and qfried are the variable i want to update
qfried = qfried + 1
tfried = tfried + pfried
If ListAllOrders.Items.Contains("Fried Chicken - P" & Convert.ToString(tfried) & " Quantity (" & Convert.ToString(qfried) & ")") Then
ListAllOrders.Items.Remove("Fried Chicken - P" & Convert.ToString(tfried) & " Quantity (" & Convert.ToString(qfried) & ")")
ListAllOrders.Items.Add("Fried Chicken - P" & tfried & " Quantity - (" & qfried & ")")
i += 1
Else
ListAllOrders.Items.Add("Fried Chicken - P" & tfried & " Quantity - (" & qfried & ")")
End If
End If
End Sub
I expect that the information would be updated
The remove option of the ListBox does not work with Strings, but with ListBoxItems. For you to remove it, you can do it like this:
For Each item In ListAllOrders.Items
If item.Contains(desiredStringToRemove) Then
ListAllOrders.Items.Remove(item)
Exit for
End If
Next

Paging in SharePoint with SPSiteDataQuery

I'm attempting to write a WebPart for SharePoint that will display a list of the most recent uploads and modifications to the Site (including all Document Lists)
To that end I have created an SPGridView and I am using an SPSiteDataQuery to populate that with my (customisable) selected Lists. I'm aware that SPQuery has the ListItemCollectionPosition, but as far as I know this will not work for multiple lists, and doing one at a time ruins sorting/paging.
This is a snippet of what I have:
Dim query As New SPQuery()
Dim lists As String = "<Lists ServerTemplate='101'>"
For Each li As Guid In SelectedLists ' Personalisable Property
lists &= "<List ID='" & li.ToString & "' />"
Next
lists &= "</Lists>"
query.Lists = lists
query.RowLimit = 30 ' This will be the page size and is temporarily hardcoded
' These Id's are all SPBuildInFieldId's converted ToString
query.ViewFields = "<FieldRef ID'" & _filenameId & "' />" &
"<FieldRef ID='" & _modifiedId & "' />" &
"<FieldRef ID='" & _modifiedById & "' />" &
"<FieldRef ID='" & _versionId & "' />" &
"<FieldRef ID='" & _checkedOutToId & "' />" &
"<FieldRef ID='" & _fileSizeId & "' />" &
"<FieldRef ID='" & _createdId & "' />" &
"<FieldRef ID='" & _createdById & "' />"
query.Webs = "<Webs Scope='Recursive' />"
query.Query = "<OrderBy><FieldRef ID='" & _modifiedId & "' Ascending='FALSE' /></OrderBy>"
Dim temp as DataTable = objWeb.GetSiteData(query)
For Each row As DataRow In temp.Rows
Dim aRow = dtTable.Rows.Add()
' Get List Information
Dim listId As Guid = New Guid(row.Item("ListId").ToString)
Dim thisList As SPList = objWeb.Lists(listId)
Dim fileName As String = row.Item(_filenameId).ToString
aRow.Item("DocIcon") = "/_layouts/15/images/" & Utilities.SPUtility.MapToIcon(objWeb, fileName, "")
aRow.Item("FileName") = fileName
aRow.Item("FileLink") = objWeb.Url & "/" & thisList.Title & "/" & fileName
aRow.Item("ListName") = thisList.Title
aRow.Item("ListLink") = objWeb.Url & "/" & thisList.Title
aRow.Item("Modified") = row.Item(_modifiedId).ToString
aRow.Item("ModifiedBy") = New SPFieldLookupValue(row.Item(_modifiedById).ToString).LookupValue
aRow.Item("Version") = row.Item(_versionId).ToString
aRow.Item("CheckedOutTo") = New SPFieldLookupValue(row.Item(_checkedOutId).ToString).LookupValue
aRow.Item("FileSize") = row.Item(_fileSizeId).ToString
aRow.Item("Created") = row.Item(_createdId).ToString
aRow.Item("Author") = New SPFieldLookupValue(row.Item(_createdById).ToString).LookupValue
Next
This DataTable is set to the source of my SPGridView, and that allows paging (I am currently using an SPGridViewPager), but it will always return the full collection of documents from the query, which is going to cause some overhead once there are a lot of documents.
What I'd like is to be able to paginate in the query itself so that it only returns correct documents for the current page (~30 at a time), but I'm hitting a wall trying to achieve this.
Is there a solution I'm missing that will allow me to both query a predetermined set of lists in modified order, and also paginate at query time?
Thanks in advance and apologies for any bad wording/formatting, this is my first question on this site.
There is a workaround for this case, while it may not 'best choice' if you have huge data volume.
"Imagine If we want to display 25 records in a page & the user wants to navigate to page no 2.
uint recordsPerPage = 25;
uint pageNumber = 2;
So the rowLimit property of our query should be 25 * 2 = 50."
https://nivas07.wordpress.com/2010/06/15/paging-using-spsitedataquery/

entity to linq where clause

I am using entity to linq
Please find my linq query -
Using lcntxRT60Entities As New RT60Entities(EntityConnection)
Dim lstrDocumentWhereClause As String
lstrDocumentWhereClause = astrDocumentWhereClause & " AND it.TransactionType = " + aintTransactionType.ToString + " AND it.VoidIndicator = 0"
lstrDocumentWhereClause = lstrDocumentWhereClause & " AND it.RtRouteDetails.RouteNumber = " + aintRouteNumber.ToString
If adatFromDate.ToString IsNot Nothing And adatToDate.ToString IsNot Nothing Then
adatToDate = adatToDate.AddHours(23).AddMinutes(59).AddSeconds(59)
lstrDocumentWhereClause = lstrDocumentWhereClause & " AND (it.TransactionDateTime BETWEEN DATETIME'" & Convert.ToDateTime(adatFromDate).ToString("yyyy-MM-dd HH:mm") & "' AND DATETIME'" & Convert.ToDateTime(adatToDate).ToString("yyyy-MM-dd HH:mm:ss") & "')"
End If
Dim Documents = From CTH In lcntxRT60Entities.RtCstTrnHeader.Where(lstrDocumentWhereClause) _
Join C In lcntxRT60Entities.RtCustomer.Where(astrCustomerWhereClause) On CTH.RtCustomer.CustomerID Equals C.CustomerID _
Select CTH, C _
Order By CTH.RouteKey, CTH.VisitKey, CTH.TransactionKey
Dim DocumentDetails = From Document In Documents.ToList _
Select Document.CTH
Return DocumentDetails.Skip(aintStartRow).Take(aintPageSize).ToList
i have problem with my where clause -
lstrFilterCriteria = "it.DocumentPrefix + it.DocumentNumber LIKE '" & lstrValue.ToString().Trim() & "'"
this throw conversion error .
If i use this
lstrFilterCriteria = "it.DocumentPrefix+SqlFunctions.StringConvert((integer)it.DocumentNumber) LIKE '" & lstrValue.ToString().Trim() & "'"
its throw syntax error .
how to convert concatenate this two column .
Document prefix is string and document number is integer .
Please suggest .
Thnaks
Using lcntxRT60Entities As New RT60Entities(EntityConnection)
Dim query=lcntxRT60Entities.RtCstTrnHeader
.Where(t=>t.TransactionType==aintTransactionType)
.Where(t=>t.VoidIndicator==0)
If adatFromDate.ToString IsNot Nothing And adatToDate.ToString IsNot Nothing Then
adatToDate = adatToDate.AddHours(23).AddMinutes(59).AddSeconds(59)
query=query.Where(t=>t.TransactionDateTime>adatFromDate && t.TransactionDateTime<adatToDate);
End If
query=query
.OrderBy(t=>t.RouteKey)
.ThenBy(t=>t.Visitkey)
.ThenBy(t=>t.TransactionKey)
Return query.Skip(aintStartRow).ToList
You will have to add in your own parameters for whatever astrDocumentWhereClause and astrCustomerWhereClause may contain before this as you didn't supply it in your example code.

Insert SQL Query not executed

I am doing the programming on my computer and it works fine-the program, the database itself, inserting to the database is also working fine. But when I publish it and install the program on another computer. It crashes and does not execute the INSERT command.
Here is my code.
Private Sub cmdBlank_Click(sender As System.Object, e As System.EventArgs) Handles cmdBlank.Click
strTariff1 = txtPart1.Text & " " & txtPName1.Text & " " & txtQty1.Text & " " & txtU1.Text
strTariff2 = txtPart2.Text & " " & txtPName2.Text & " " & txtQty2.Text & " " & txtU2.Text
strTariff3 = txtPart3.Text & " " & txtPName3.Text & " " & txtQty3.Text & " " & txtU3.Text
strTariff4 = txtPart4.Text & " " & txtPName4.Text & " " & txtQty4.Text & " " & txtU4.Text
'strTariff5 = txtPart5.Text & " " & txtPName5.Text & " " & txtQty5.Text & " " & txtU5.Text
Call saveToDb()
frmreportax.Show()
End Sub
Private Function saveToDb()
conn.Close()
Dim cmdAdd, cmdCount, cmdAdd2 As New iDB2Command
Dim sqlAdd, sqlCount, sqlAdd2 As String
Dim curr1, curr2, curr3, curr4 As String
Dim count As Integer
conn.ConnectionString = str
conn.Open()
'Check for duplicate entry
sqlCount = "SELECT COUNT(*) AS count FROM cewe WHERE transport=#transport AND blnum=#blnum"
With cmdCount
.CommandText = sqlCount
.Connection = conn
.Parameters.AddWithValue("#transport", frmPart1.txtTransport.Text)
.Parameters.AddWithValue("#blnum", frmPart1.txtNo.Text)
End With
count = Convert.ToInt32(cmdCount.ExecuteScalar())
If count <> 0 Then
MsgBox("Duplicate Entry: " & frmPart1.txtTransport.Text, vbOKOnly + vbExclamation)
Else
sqlAdd = "INSERT INTO cewe (page) " & _
"VALUES (#page) "
With cmdAdd
.Parameters.AddWithValue("#page", Val(frmPart1.txtPage.Text))
.CommandText = sqlAdd
.Connection = conn
.ExecuteNonQuery()
End With
end if
cmdAdd.Dispose()
cmdAdd2.Dispose()
conn.Close()
end function
Please tell me what I am doing wrong? When I run and install the program on my PC, it works perfectly fine. But when I run/install it on another PC, it crashes after the cmdBlank is clicked.
There could be a number of things causing the issue but the first place to look is any error logs or crash report that may give some indication of the problem. Try debugging or logging to get a better picture. Beyond that there are some small suggestions that may help below.
Does the other computer have access to the database you are pointing to? Is the database connection pointing to localhost? In which case you will want to ensure that you have the same credentials (host, username, password, port etc.) set up on the database server on new computer. Are database drivers installed on new computer? What are the fundamental differences between the two machines?
AS400 iSeries DB2 needs to be updated to version 6.xx.0800 and did the tweak!
Installer can be found here
http://www-03.ibm.com/systems/power/software/i/access/windows_sp.html
Problem solved!

datatype mismatch in criteria expression in MS Access

I am creating form in access in which i have to implement cascading combo boxes , data in lower combo box is dependent on its parent value selected by user. Here is form
on left side is structure of the table and on right side is form. Problem is I am getting error of data type mismatch , unable to understand why this is happening. In the afterupdate event of Diametre of Drill I am populating cutting speed . Whenever I press drop down of Cutting Speed "Datatype mismatch in criteria expression" occurs. Here is code of afterupdate event of Diametre of Drill
Private Sub cboDiameterDrilling_AfterUpdate()
cboCuttingSpeedDrilling.RowSource = "Select DISTINCT tblDrilling.cuttingSpeed " & _
"FROM tblDrilling " & _
`"WHERE tblDrilling.materials = '" & cboMaterialDrilling.Value & "' AND tblDrilling.diaOfDrill = '` `cboDiameterDrilling.Value ' " & _`
"ORDER BY tblDrilling.cuttingSpeed;"
End Sub
I think problem is in WHERE Clause . Any help would be greatly appreciated. Thank you
You've surrounded the reference to the object's value (cboDiameterDrilling.Value ) in single quotes.
AND tblDrilling.diaOfDrill = ' & cboDiameterDrilling.Value & "'"
Solution : AND tblDrilling.diaOfDrill = " & cboDiameterDrilling.Value & " " & _
I think you missed a ". Try:
Private Sub cboDiameterDrilling_AfterUpdate()
cboCuttingSpeedDrilling.RowSource = "Select DISTINCT tblDrilling.cuttingSpeed " & _
"FROM tblDrilling " & _
`"WHERE tblDrilling.materials = '" & cboMaterialDrilling.Value & "' AND tblDrilling.diaOfDrill = '" & cboDiameterDrilling.Value & "' " & _
"ORDER BY tblDrilling.cuttingSpeed;"
End Sub