Item cannot be found in the collection to the requested name or ordinal - datagrid

Upon clicking a client from the datagrid, all the clients informaition are loaded in the right side of the form, all seems to be doing pretty well.[https://i.stack.imgur.com/Mv5ZL.png][1]
and whenever I click the add payment button, it will open the payment form.
[https://i.stack.imgur.com/DmznP.png][2]
but whenever I try to choose another client, it will produce a runtime error '3265'. and when I click the debug button, the fields to be filled seemed to have all the information they needed. Why is this error showing up? [https://i.stack.imgur.com/YuLg5.png][3]
Here is my code in loading all the clients
Private Sub Form_Load()
Set Connect = New Class1
Set rx = New ADODB.Recordset
rx.Open "SELECT * FROM allclients ORDER by dateCreated ASC", con, 3, 3
lblLNumberRecords.Caption = Format(rx.RecordCount, "###,###,###.##")
Set DatCUSTOMERS.DataSource = rx
Me.Show
clearfields
End Sub
and here is my code when clicking a client:
Private Sub DatCUSTOMERS_RowColChange(LastRow As Variant, ByVal LastCol As Integer)
Unload frmPaymentRecur
lblID = rx.Fields("id")
txtClientID = rx.Fields("clientCode")
txtFirstName = rx.Fields("fname")
txtLastName = rx.Fields("lname")
txtMname = rx.Fields("mname")
txtExtension = rx.Fields("extName")
txtPin = rx.Fields("pinNo")
txtDesignation = rx.Fields("designation")
txtContactNo = rx.Fields("contactNo")
txtAddress = rx.Fields("address")
txtAge = rx.Fields("Age")
txtSalary = rx.Fields("salary")
cmbAssociation.Text = rx.Fields("fieldTypeTitle")
cmbChoices.Text = rx.Fields("fieldNameTitle")
cmdEdit.Enabled = True
cmdAddLoan.Enabled = True
cmdPayments.Enabled = True
End Sub
here is my code when clicking the add payment button:
Private Sub cmdPayments_Click()
Dim flagClients, dateFlag, loanFlag As Integer
flagClients = 1
dateFlag = 1
loanFlag = 1
frmPaymentRecur.lbldateFlag.Caption = dateFlag
frmPaymentRecur.lblLoanFlag.Caption = loanFlag
frmPaymentRecur.txtClientID = rx.Fields("clientCode")
frmPaymentRecur.txtFolderNo = rx.Fields("folderCode")
frmPaymentRecur.txtFullName = rx.Fields("Name")
frmPaymentRecur.txtAssociation = rx.Fields("fieldNameTitle")
frmPaymentRecur.txtSalary = rx.Fields("salary")
frmPaymentRecur.CmbSelectPaymentType.Text = "All Loans"
frmPaymentRecur.lblFlag = flagClients
If rx.State = 1 Then rx.Close
rx.Open "SELECT DISTINCT(`Loan Type`) FROM paymentview WHERE `Client Code` = '" & Trim$(txtClientID.Caption) & "'", con, 3, 3
With rx
Do While Not .EOF
frmPaymentRecur.CmbSelectPaymentType.AddItem ![Loan Type]
.MoveNext
Loop
.Close
End With
frmPaymentRecur.Show
End Sub

In your Add Payment code, at the end, you are closing the rx recordset. It will be empty when you try updating your controls.
You've also populated the recordset with data form a different table, paymentview, where id probably doesn't exist.
You should create a separate recordset to handle your payment code instead of reusing the rx recordset.

Related

Devexpress Xtragrid TileView

I'm using Devexpress Xtragrid TileView module.
Basically I want my code works like this :
user input member ID on the upper left textbox and press load.
If they exists, then a Tile will be appeared.
A tile should contain : Name, Status, member ID and a photo.
If user press load again (either same ID or another ID) a Tile will be added also, and so on. Unless they press Clear & Load, It should be only 1 latest tile left.
So, I'm able to produce up to Step 3.
But I couldn't be able to load the picture.
The picture itself, It's not a byte array. It's a Image path.
e.q : D:/test/1.jpg
So, how do I load the picture?
Protected Overridable Sub InitData()
Try
Dim homesTable = ds.Tables(0)
homesTable.Columns.Add("ImageCol")
For Each row_Renamed As DataRow In homesTable.Rows
Dim img As Image = Image.FromFile(row_Renamed("memberPhoto")) 'I tried this, but didn't work
row_Renamed("ImageCol") = img
Next row_Renamed
GridControl1.DataSource = homesTable
Catch
End Try
End Sub
Private Sub setupTile()
'For i = 0 To j - 1
Try
TileView1.BeginUpdate()
'TileView1.DataSource = ds.Tables(0)
TileView1.OptionsTiles.RowCount = 3
TileView1.OptionsTiles.Padding = New Padding(20)
TileView1.OptionsTiles.ItemPadding = New Padding(10)
TileView1.OptionsTiles.IndentBetweenItems = 20
TileView1.OptionsTiles.ItemSize = New Size(320, 170)
TileView1.Appearance.ItemNormal.ForeColor = Color.White
TileView1.Appearance.ItemNormal.BorderColor = Color.Transparent
'Setup tiles template
Dim leftPanel As New TileViewItemElement()
Dim splitLine As New TileViewItemElement()
Dim nameCaption As New TileViewItemElement()
Dim nameValue As New TileViewItemElement()
Dim statusCaption As New TileViewItemElement()
Dim statusValue As New TileViewItemElement()
Dim RGPCaption As New TileViewItemElement()
Dim RGPvalue As New TileViewItemElement()
Dim imageTile As New TileViewItemElement()
TileView1.TileTemplate.Add(leftPanel)
TileView1.TileTemplate.Add(splitLine)
TileView1.TileTemplate.Add(nameCaption)
TileView1.TileTemplate.Add(nameValue)
TileView1.TileTemplate.Add(statusCaption)
TileView1.TileTemplate.Add(statusValue)
TileView1.TileTemplate.Add(RGPCaption)
TileView1.TileTemplate.Add(RGPvalue)
TileView1.TileTemplate.Add(imageTile)
'
'nameValue.Text = ""
'statusValue.Text = ""
'RGPvalue.Text = ""
'imageTile.Image = Nothing
'
leftPanel.StretchVertical = True
leftPanel.Width = 190
leftPanel.TextLocation = New Point(-10, 0)
leftPanel.Appearance.Normal.BackColor = Color.FromArgb(58, 166, 101)
'
splitLine.StretchVertical = True
splitLine.Width = 3
splitLine.TextAlignment = TileItemContentAlignment.Manual
splitLine.TextLocation = New Point(190, 0)
splitLine.Appearance.Normal.BackColor = Color.White
'
nameCaption.Text = "Name"
nameCaption.TextAlignment = TileItemContentAlignment.TopLeft
nameCaption.Appearance.Normal.FontSizeDelta = -1
'
nameValue.Column = TileView1.Columns("preferredName")
nameValue.AnchorElement = nameCaption
nameValue.AnchorIndent = 2
nameValue.MaxWidth = 200
nameValue.Appearance.Normal.FontStyleDelta = FontStyle.Bold
'nameValue.Text = ds.Tables(0).Rows(i)("preferredName").ToString
'
statusCaption.Text = "Status"
statusCaption.AnchorElement = nameValue
statusCaption.AnchorIndent = 14
statusCaption.Appearance.Normal.FontSizeDelta = -1
'
statusValue.Column = TileView1.Columns("memberStatus")
statusValue.AnchorElement = statusCaption
statusValue.AnchorIndent = 2
statusValue.Appearance.Normal.FontStyleDelta = FontStyle.Bold
'statusValue.Text = ds.Tables(0).Rows(i)("memberStatus").ToString
'
RGPCaption.Text = "RGP"
RGPCaption.AnchorElement = nameValue
RGPCaption.AnchorIndent = 65
'RGPCaption.TextLocation
'RGPCaption.Appearance.Normal.FontSizeDelta = -1
RGPCaption.Appearance.Normal.Font = New Font("Segoe UI Semibold", 12.0F, System.Drawing.FontStyle.Regular)
'
RGPvalue.Column = TileView1.Columns("code")
RGPvalue.AnchorElement = RGPCaption
RGPvalue.AnchorIndent = 1
RGPvalue.TextAlignment = TileItemContentAlignment.BottomLeft
RGPvalue.Appearance.Normal.Font = New Font("Segoe UI Semilight", 25.75F, System.Drawing.FontStyle.Regular)
'RGPvalue.Text = ds.Tables(0).Rows(i)("code").ToString
'
imageTile.Column = TileView1.Columns("ImageCol")
imageTile.ImageSize = New Size(120, 170)
imageTile.ImageAlignment = TileItemContentAlignment.MiddleRight
imageTile.ImageScaleMode = TileItemImageScaleMode.Stretch
imageTile.ImageLocation = New Point(12, 0)
Catch ex As Exception
XtraMessageBox.Show(ex.Message)
Finally
TileView1.EndUpdate()
End Try
'Next
End Sub
Private Sub loadBtn_Click(sender As Object, e As EventArgs) Handles loadBtn.Click
initData()
setupTile()
End Sub
Maybe it's too late but in my case only need to read file from disk and assign to a byte() column.
First of all, table column should be byte array so replace:
homesTable.Columns.Add("ImageCol")
for:
homesTable.Columns.Add(New DataColumn("ImageCol", GetType(Byte)))
Then I'd try to replace:
row_Renamed("ImageCol") = img
for:
row_Renamed("ImageCol") = IO.File.ReadAllBytes(row_Renamed("memberPhoto"))
That would load disk file to byte array and shown in tile. I'd check if file exists to avoid exceptions.
That's what I do to load image from disk.
Hope it helps.

Multiple record increase by one

I have this code to access:
Option Compare Database
Public Sub batchAdd(records As Integer)
Dim db As DAO.Database
Dim rs As DAO.Recordset
Dim i As Integer
Set db = CurrentDb
Set rs = db.OpenRecordset("tblMeters")
i = 1
Do While i <= records
rs.AddNew
rs!value1 = Me.value1
rs!Ticket = Me.Ticket
rs!value2 = Me.value2
rs!value3 = Me.value3
rs!value4 = Me.value4
rs!value5 = Me.value5
rs!value6 = Me.value6
rs!value7 = Me.value7
rs.Update
i = i + 1
Loop
rs.Close
Set rs = Nothing
Set db = Nothing
End Sub
Private Sub cmdAddRecords_Click()
batchAdd Me.txtRecords
Me.tblMeters_sub.Requery
End Sub
My question was how to increase the ticket value of +1 for each record inserted.
Example: If I insert the ticket with a value of 1 to 10 times, the first time will be 1 and the second 2, then 3 .... how do I change this code for the ticket value?
Adjust this line to:
rs!Ticket = i

How to change name of control in server side?

I,ve created a dropdown in server side. my code is :
Dim dd As DropDownList = New DropDownList()
Dim n As Integer
Dim clsCareer As New merchant
Dim _dr_fill_dll_senf As SqlClient.SqlDataReader
dd.Items.Add("Senf")
dd.SelectedItem.Value = "0"
_dr_fill_dll_senf = clsCareer.GetAllParentSenf()
dd.SelectedItem.Value = selectedValue
n = 1
Do While _dr_fill_dll_senf.Read
dd.Items().Add(_dr_fill_dll_senf.Item("description") + " (" + _dr_fill_dll_senf.Item("code") + ")")
dd.Items(n).Value = _dr_fill_dll_senf.Item("code")
n = n + 1
Loop
_dr_fill_dll_senf.Close()
Panel1.Controls.Add(dd)
My problem is: I want to set name of this dropdown in server side.... but when page is load name is created automatically but i want set name custom

vb.net insert Code runs twice?

I have a aspx form in vs2012(vb.net) where an incident is created and after inserting the records into the table it passes the newly created ID into second table where it is the Foreign Key. However the insert code runs twice and creates two entries in the second table. I tried to pass the ID into a function and exiting the function but that did not work either. Any idea?
I do not want duplicate entry for Incident ID in the second table so I am trying to insert the Incident ID into the second table so then I can update that second table.
Protected Sub btnCreateIncident_Click(sender As Object, e As EventArgs) Handles btnCreateIncident.Click
Try
InciDS.InsertParameters("PatronID").DefaultValue = strPID
InciDS.InsertParameters("PatronName").DefaultValue = PatName
InciDS.InsertParameters("Inci_type").DefaultValue = ddInciCatList.SelectedItem.Text.Trim()
InciDS.InsertParameters("Inci_date").DefaultValue = txtDate.Text.Trim()
InciDS.InsertParameters("Inci_time").DefaultValue = ddEventHour.SelectedItem.Text.Trim() + ":" + ddEventMin.SelectedItem.Text.Trim()
InciDS.InsertParameters("Active").DefaultValue = "True"
InciDS.InsertParameters("LocDescription").DefaultValue = LocDesc.Text.Trim()
InciDS.InsertParameters("Location").DefaultValue = ddLocation.SelectedItem.Text.Trim()
InciDS.InsertParameters("Library").DefaultValue = ddBldg.SelectedItem.Text.Trim()
InciDS.InsertParameters("Description").DefaultValue = txtInciDesc.Content
InciDS.InsertParameters("Action_Taken").DefaultValue = txtActionTaken.Content
InciDS.InsertParameters("Involved_patrons").DefaultValue = txtPatronDesc.Content
InciDS.InsertParameters("FollowUp").DefaultValue = txtFollowUp.Content
InciDS.InsertParameters("Created_By").DefaultValue = strCreatedBy.Text.Trim()
InciDS.Insert()
Catch ex As Exception
MsgBox(ex.Message)
End Try
PassParameters = strPID
PassParameters = PassParameters + "&value2=" + PatName
PassParameters = PassParameters + "&value3=" + NewID
Response.Redirect("~/IntermediatePage.aspx?value1=" & PassParameters, False)
End Sub
Protected Sub InciDS_Inserted(ByVal sender As Object, ByVal e As SqlDataSourceStatusEventArgs) Handles InciDS.Inserted
'get the newly id of the newly created incident
NewID = e.Command.Parameters("#Inci_ID").Value.ToString
PoliceDS.InsertParameters("IncidentID").DefaultValue = NewID
PoliceDS.Insert()
'Newid = Convert.ToInt16(e.Command.Parameters("#Inci_ID").Value)
End Sub

Converting null string to date

I have searched high and low to no avail, and this is last step before completing my project so please help! Thanks in advance!
The user will select an entry in a gridview, which then redirects them to a form that is populated with the data from the selected row (thus making the gridview editable in a more user friendly way). Null values are accepted by the DB and I would like to show null date values as blank (or " ") in the corresponding text boxes. Instead I get the error:
Conversion from type 'DBNull' to type 'Date' is not valid.
Here is my code:
'preceded by connection code
Dim sqlcmd As String = "SELECT * from Master WHERE RecNum = #recnum"
'Dim sqlCmd As New OleDb.OleDbCommand("SELECT * from Master WHERE RecNum = #recnum", connection)
Dim FileCommand3 As New OleDb.OleDbCommand(sqlcmd, connection)
FileCommand3.Parameters.AddWithValue("#recnum", user)
Dim Reader3 As OleDb.OleDbDataReader = FileCommand3.ExecuteReader()
If Reader3.Read Then
stock = myCStr(Reader3("StockNum"))
make = myCStr(Reader3("Make"))
color = myCStr(Reader3("Color"))
stockin = myCStr(Reader3("Stockin"))
ucistart = myCStr(Reader3("UCIStartDate"))
repairs = Reader3("Repairs")
tires = Reader3("tiresneeded")
onlot = Reader3("onlot")
sold = Reader3("sold")
year = myCStr(Reader3("year"))
model = myCStr(Reader3("model"))
location = Reader3("location")
srvcRO = myCStr(Reader3("svcROnum"))
ucicompldate = myCStr(Reader3("uciestcompletedate"))
collRO = myCStr(Reader3("collisionROnum"))
other = myCStr(Reader3("other"))
offprop = Reader3("offProperty")
detail = (Reader3("detail")
End If
connection.Close()
SoldCheckBX.Checked = sold
DetailTXTbox.Text = detail
'etc, etc
End Sub
I used the function mycstr to fix the dbnull to string error but it does not seem as simple to adapt to "date" data type
Function myCStr(ByVal test As Object) As String
If isdbnull(test) Then
Return ("")
Else
Return CStr(test)
End If
End Function
try this when you read the values from the reader with all your dates, this will first test to see if the date is dbnull, if it is then it will assign a nothing value and you should get your desired empty cell, otherwise it will show the date:
ucistart = IIf(reader3("UCIStartDate") Is DBNull.Value, Nothing, reader3("UCIStartDate"))
Have you tried using the Convert.IsDBNull function?
Here is the official documentation.

Resources