Need a little help here.
I just want to add a Group Item with Item List on it using the QBFC12 but am having a trouble with it. I have tried creating the same method like this with Inventory Assembly and it works well. but this one makes me feel terrible. When the request is processed, it return error telling that there're missing fields on the request. Hope anyone can help me out with this.
Thanks
Here's my code below:
Dim msgSetRequest As IMsgSetRequest
Dim QBSM As New QBSessionManager
Try
With QBSM
.OpenConnection("", "QB Test")
.BeginSession("", ENOpenMode.omDontCare)
End With
Catch ex As Exception
Throw New Exception(ex.Message)
Return False
End Try
msgSetRequest = QBSM.CreateMsgSetRequest("US", 8, 0)
msgSetRequest.Attributes.OnError = ENRqOnError.roeStop
msgSetRequest.ClearRequests()
Dim gAdd As IItemGroupAdd = msgSetRequest.AppendItemGroupAddRq
gAdd.IsActive.SetValue(True)
gAdd.Name.SetValue("Group Name")
gAdd.ItemDesc.SetValue("Group Description")
For Each gListItem As clsInventoryGroupItem In gItem.InventoryGroupItemList
Dim gItemAdd As IItemGroupLine = msgSetRequest.AppendItemGroupAddRq.ItemGroupLineList.Append
gItemAdd.ItemRef.FullName.SetValue(gListItem.ItemRef)
gItemAdd.Quantity.SetValue(gListItem.Quantity)
Next
Dim response As IMsgSetResponse = QBSM.DoRequests(msgSetRequest)
If response.ResponseList.GetAt(0).StatusCode = 0 Then
MessageBox.Show("Success")
else
MessageBox.Show("An Error occurred while inserting Group")
endif
I think the problem is how you are adding your group lines, but haven't tested it yet. Instead of using ItemGroupLineList.Append from the msgSetRequest, you should call it from your IItemGroupAdd object, gAdd. Here's what I came up with, but didn't test it.
Dim msgSetRequest As IMsgSetRequest
Dim QBSM As New QBSessionManager
Try
With QBSM
.OpenConnection("", "QB Test")
.BeginSession("", ENOpenMode.omDontCare)
End With
Catch ex As Exception
Throw New Exception(ex.Message)
Return False
End Try
msgSetRequest = QBSM.CreateMsgSetRequest("US", 8, 0)
msgSetRequest.Attributes.OnError = ENRqOnError.roeStop
msgSetRequest.ClearRequests()
Dim gAdd As IItemGroupAdd = msgSetRequest.AppendItemGroupAddRq
gAdd.IsActive.SetValue(True)
gAdd.Name.SetValue("Group Name")
gAdd.ItemDesc.SetValue("Group Description")
For Each gListItem As clsInventoryGroupItem In gItem.InventoryGroupItemList
Dim gItemAdd As IItemGroupLine = gAdd.ItemGroupLineList.Append
gItemAdd.ItemRef.FullName.SetValue(gListItem.ItemRef)
gItemAdd.Quantity.SetValue(gListItem.Quantity)
Next
Dim response As IMsgSetResponse = QBSM.DoRequests(msgSetRequest)
If response.ResponseList.GetAt(0).StatusCode = 0 Then
MessageBox.Show("Success")
else
MessageBox.Show("An Error occurred while inserting Group")
endif
Related
I've got this error that said String was not recognized as a valid DateTime, can anyone help me what's wrong here?
Dim Br As New BL.Bridge
Me.DataSource = Br.List(DateTime.ParseExact(Me.txtTempo.Text, "dd-MM-yyyy", CultureInfo.InvariantCulture)) 'error is right here
Me.ReportPath = "~/report/JaTem.rpt"
Me.HasPrintButton = True
Me.ShowGroupTree = False
If DataSource.Rows.Count > 0 Then
Me.HasPrintButton = True
Server.Transfer("~/report/rpt.aspx")
Else
lblMessage.Text = "No Data!"
End If
if txtTempo is filled with date it's work, but when txtTempo is empty, it's getting error
The DateTime.ParseExact method that you are using will give an error when it runs into data that it can't handle. You need to do one of 3 things,
validate the data before using the ParseExact method
use exception handling to catch the error and notify your user
or you can use the DateTime.TryParseExact which will give you a Boolean result to indicate if the method succeeded. You would use it something like this.:
Imports System.Globalization
Module Module1
Sub Main()
Dim Date1Data As String = ""
Dim Date2Data As String = "25-09-2015"
Dim result As DateTime
If DateTime.TryParseExact(Date1Data, "dd-MM-yyyy", CultureInfo.InvariantCulture, DateTimeStyles.None, result) Then
'handle it here
Else
Console.WriteLine("Format Error")
End If
If DateTime.TryParseExact(Date2Data, "dd-MM-yyyy", CultureInfo.InvariantCulture, DateTimeStyles.None, result) Then
Console.WriteLine(result) 'handle it here
Else
Console.WriteLine("Format Error")
End If
Console.ReadLine()
End Sub
End Module
or modifying your code something like this should work.
Dim Br As New BL.Bridge
Dim result as Date
If DateTime.TryParseExact(Me.txtJatem.Text, "dd-MM-yyyy", CultureInfo.InvariantCulture, DateTimeStyles.None, result) Then
Me.DataSource = Br.List(result) 'error is right here
Me.ReportPath = "~/report/JaTem.rpt"
Me.HasPrintButton = True
Me.ShowGroupTree = False
If DataSource.Rows.Count > 0 Then
Me.HasPrintButton = True
Server.Transfer("~/report/rpt.aspx")
Else
lblMessage.Text = "No Data!"
End If
Else
lblMessage.Text = "Format Error, please check input and try again"
End If
i created 2 reports billa4.rdlc and billa5.rdlc and i want to load one of the report to the reportviewer as per the selection of option of combobox by user .
please help me for this .
the below code is loading the billa4.rdlc
Try
Dim P2 As New ReportParameter("pbillnum", billnoprint)
Me.DataTable1TableAdapter.Fill(Me.billdata.DataTable1, billnoprint)
Me.ReportViewer1.LocalReport.SetParameters(New ReportParameter() {P2})
Me.ReportViewer1.SetDisplayMode(DisplayMode.PrintLayout)
Me.ReportViewer1.ZoomMode = ZoomMode.FullPage
Me.ReportViewer1.RefreshReport()
Catch ex As Exception
MsgBox("error")
End Try
What have you tried? Don't set up an report source directly from the design mode, do it by code.
Maybe something like this:
if( combooption.SelectedValue = 0) Then
Dim P2 As New ReportParameter("pbillnum", billnoprint)
Me.DataTable1TableAdapter.Fill(Me.billdata.DataTable1, billnoprint)
Me.ReportViewer1.ViewReport("billa4.rdlc")
Me.ReportViewer1.LocalReport.SetParameters(New ReportParameter() {P2})
Me.ReportViewer1.SetDisplayMode(DisplayMode.PrintLayout)
Me.ReportViewer1.ZoomMode = ZoomMode.FullPage
Me.ReportViewer1.RefreshReport()
else
Dim P2 As New ReportParameter("pbillnum", billnoprint)
Me.DataTable1TableAdapter.Fill(Me.billdata.DataTable1, billnoprint)
Me.ReportViewer1.ViewReport("billa5.rdlc")
Me.ReportViewer1.LocalReport.SetParameters(New ReportParameter() {P2})
Me.ReportViewer1.SetDisplayMode(DisplayMode.PrintLayout)
Me.ReportViewer1.ZoomMode = ZoomMode.FullPage
Me.ReportViewer1.RefreshReport()
End if
I'm running an AD query to pull selected attributes from a users profile. I'm selecting extensionAttribute3, 4, 5, 6, 7 & 8. Although I can get the result to display as text, I'd like to set the selected vlaue of a combobox to the results.
So extension attribute 3, 5 & 7 = security questions, 4, 6 & 8 are the answers. I have 3 comboboxes, each with a list of 15 possible security questions users can select from, and then provide answers to. I've got my script to update AD with the questions & answers selected. However when I run the application again, I'd like to pull the existing questions from extensionAttribute 3, 5 & 7, as set as the default selected foreach combobox.
Current AD Query Code:
Private Function GetUserProperties()
Dim ADName As String = GetLogonName()
Dim CurrentPIN As String = Nothing
Dim bSuccess As Boolean = False
Dim dirEntry As DirectoryEntry = GetDirectoryEntry()
Dim dirSearcher As DirectorySearcher = New DirectorySearcher(dirEntry)
Dim Q1Value As String = Nothing
dirSearcher.Filter = ("(samAccountName=" & ADName & ")")
dirSearcher.PropertiesToLoad.Add("extensionAttribute3")
dirSearcher.PropertiesToLoad.Add("extensionAttribute4")
dirSearcher.PropertiesToLoad.Add("extensionAttribute5")
dirSearcher.PropertiesToLoad.Add("extensionAttribute6")
dirSearcher.PropertiesToLoad.Add("extensionAttribute7")
dirSearcher.PropertiesToLoad.Add("extensionAttribute8")
dirSearcher.SearchScope = SearchScope.Subtree
Try
Dim dirResult As SearchResult = dirSearcher.FindOne()
bSuccess = Not (dirResult Is Nothing)
If dirResult Is Nothing OrElse dirResult.GetDirectoryEntry.Properties("extensionAttribute3").Value Is Nothing Then
Return "<not set>"
Else
Q1Value = dirResult.GetDirectoryEntry.Properties("extensionAttribute3").Value.ToString
Q1ComboBox.SelectedIndex = Q1Value
End If
Catch ex As Exception
bSuccess = False
MsgBox("No Connection to the domain." & Environment.NewLine & "Please connect to corporate network & try again.", MsgBoxStyle.Critical, "Network Error")
Application.Exit()
End Try
Return False
End Function
It's really hard to format code in comments, i put them here instead.
I'm not VB programmer, may have syntax error.
You don't provide code for extensionAttribute4-8, so it's hard to find what's wrong with them. Do you mean for extensionAttribute4-8, just repeating the if-else block inside the try-catch does not work?
For example, you cannot get value of extensionAttribute4 below?
' code for extensionAttribute3, omitted here
....
' code for extensionAttribute4
If dirResult Is Nothing OrElse dirResult.GetDirectoryEntry.Properties("extensionAttribute4").Value Is Nothing Then
Return "<not set>"
Else
A1Value = dirResult.GetDirectoryEntry.Properties("extensionAttribute4").Value.ToString
A1ComboBox.SelectedIndex = A1Value
End If
' repeat for extensionAttribute5-8
....
For using the attribute already loaded in SearchResult, you already handle the conversion to string problem (mentioned in comment) by calling ToString. You can just do the same thing. But instead of checking dirResult.GetDirectoryEntry.Properties("...").Value Is Nothing, you should check dirResult.Properties("...").Count > 0.
Dim dirResult As SearchResult = dirSearcher.FindOne()
bSuccess = Not (dirResult Is Nothing)
If dirResult Is Nothing OrElse dirResult.Properties("extensionAttribute3").Count <= 0 Then
Return "<not set>"
Else
Q1Value = dirResult.Properties("extensionAttribute3")[0].ToString
Q1ComboBox.SelectedIndex = Q1Value
End If
I update my question here .. Am using a combo box with no of phone numbers .I want to get the phone no one by one in a variable. Now am using the below code to get the combobox values. But still now am getting the following error message System.Data.DataRowView. Please help me to fix this error. am new for vb.net.
My partial code is here ..
For i = 0 To ComboBox1.Items.Count
Dim s As String
s = Convert.ToString(ComboBox1.Items(i))
Next i
you are using an index which is zero based.
change this:
For i = 0 To ComboBox1.Items.Count
to this:
For i = 0 To ComboBox1.Items.Count - 1
This also works!
Dim stgTest = "Some Text"
Dim blnItemMatched As Boolean = False
'-- Loop through combobox list to see if the text matches
Dim i As Integer = 0
For i = 0 To Me.Items.Count - 1
If Me.GetItemText(Me.Items(i)) = stgTest Then
blnItemMatched = True
Exit For
End If
Next i
If blnItemMatched = False Then
Dim stgPrompt As String = "You entered '" & stgTypedValue & "', which is not in the list."
MessageBox.Show(stgPrompt, "Incorrect Entry", MessageBoxButtons.OK, MessageBoxIcon.Information)
Me.Text = ""
Me.Focus()
End If
Your problem probably happens here:
s = Convert.ToString(ComboBox1.Items(i))
This doesn't return the value. It returns a string representation of the object at the given index, which in your case apparently is of type System.Data.DataRowView.
You would have to cast ComboBox1.Items(i) to the approbriate type and access its Value. Or, since its a DataRowView, you can access the values throgh the appropriate column names:
Dim row = CType(ComboBox1.Items(i), System.Data.DataRowView)
s = row.Item("column_name")
Nevertheless, first of all you should definitely close and dispose the connection, no matter whether the transaction fails or succeeds. This can be done in a finally block (option 1) or with a using statement (option 2).
Option 1
// ...
con1 = New MySqlConnection(str)
con1.Open()
Try
// ...
Catch ex As Exception
Lblmsg.Text = " Error in data insertion process....." + ex.Message
Finally
con1.Close()
con1.Dispose()
End Try
Option 2
// ...
Using con1 as New MySqlConnection(str)
con1.Open()
Try
// ...
Catch ex As Exception
Lblmsg.Text = " Error in data insertion process....." + ex.Message
Finally
con1.Close()
End Try
End using
Even after long time back you will achieve this with simply by following
For Each item As Object In combx.Items
readercollection.Add(item.ToString)
Next
Please try this
For j As Integer = 0 To CboCompany.Items.Count - 1
Dim obj As DataRowView = CboCompany.Items(j)
Dim xx = obj.Row(0)
If xx = "COMP01" Then
CboCompany.SelectedIndex = j
Exit For
End If
Next
I could not find this answer online in its entirety but pieced it together. In the snippet below cbox is a ComboBox control that has the DisplayMember and ValueMember properties initialized.
Dim itemIE As IEnumerator = cbox.Items.GetEnumerator
itemIE.Reset()
Dim thisItem As DataRowView
While itemIE.MoveNext()
thisItem = CType(itemIE.Current(), DataRowView)
Dim valueMember As Object = thisItem.Row.ItemArray(0)
Dim displayMember As Object = thisItem.Row.ItemArray(1)
' Insert code to process this element of the collection.
End While
while executing this below lines i got an error. Error:
Collection was modified; enumeration operation may not execute.
Help me to solve this.
Dim i As IEnumerator
Dim item As DataGridItem
Dim bChk As Boolean = False
i = dgOfferStatus.Items.GetEnumerator
For Each item In dgOfferStatus.Items
i.MoveNext()
item = i.Current
item = CType(i.Current, DataGridItem)
Dim chkItemChecked As New CheckBox
chkItemChecked = CType(item.FindControl("chkItemChecked"), CheckBox)
If chkItemChecked.Checked = True Then
Try
bChk = True
lo_ClsInterviewProcess.JobAppID = item.Cells(1).Text
lo_ClsInterviewProcess.candId = item.Cells(9).Text
Dim str, strSchedule1, strSchedule As String
Dim dspath As DataSet
Dim candidateId As Integer
''Moving the resume to Completed folder
ObjInterviewAssessment = New ClsInterviewAssessment
dspath = ObjInterviewAssessment.GetOffComPath(CInt(lo_ClsInterviewProcess.JobAppID), "GetHoldPath")
If dspath.Tables(0).Rows.Count > 0 Then
If Not IsDBNull(dspath.Tables(0).Rows(0).Item(0)) Then
str = dspath.Tables(0).Rows(0).Item(0)
strSchedule1 = str.Replace("Hold", "Completed")
End If
End If
Dim str1 As String
str1 = Server.MapPath(str).Trim
strSchedule = Server.MapPath(strSchedule1).Trim
Dim file1 As File
If file1.Exists(str1) Then
If file1.Exists(strSchedule) Then
file1.Delete(strSchedule)
End If
file1.Move(str1, strSchedule)
End If
''
intResult = lo_ClsInterviewProcess.UpdateApproveStatus(Session("EmployeeId"), strSchedule1)
BindHoldGrid()
If intResult > 0 Then
Alert.UserMsgBox("btnsearch", "Status Updated")
Else
Alert.UserMsgBox("btnsearch", "Status not Updated")
End If
Catch ex As Exception
ExceptionManager.Publish(ex)
Throw (ex)
End Try
End If
Next
If bChk = False Then
Alert.UserMsgBox("btnsearch", "Please Select any Candidate")
End If
'Catch ex As Exception
' ExceptionManager.Publish(ex)
'End Try
End Sub
Look at this part of your code. I think it's what causes your exception.
Dim i As IEnumerator
...
Dim item As DataGridItem
...
i = dgOfferStatus.Items.GetEnumerator
For Each item In dgOfferStatus.Items
i.MoveNext()
item = i.Current ' <-- here be dragons!? '
...
Next
What you're doing seems a little strange. You iterate through the same collection (dgOfferStatus.Items) twice, once with the For Each loop, and once manually using the i iterator. Then you modify items in your collection with item = i.Current. I believe it's this assignment that causes the exception.
(I also don't understand why you would do this. This assignment seems to be completeley superfluous, since i.Current and item should be identical since both iterators are at the same position in the collection.)
The exception basically tries to tell you that you may not modify a collection while you are iterating through it. But you seem to be doing exactly that.