Affiliate Window API passing columns to Service Causes Application Crash (VB.net) - vb.net

This generates a crash, and I have no idea why?
I have very little experience using SOAP/WSDL and I think this may be why I have no idea how to even start to debug this.
Sub Main()
Dim service As AWIN.ApiService = New AWIN.ApiService
Dim columns As AWIN.getProductList
Dim AWresults() As AWIN.Product
Dim response As New AWIN.getProductListResponse
Dim total As Integer
Dim activerefine As AWIN.RefineByGroup
Dim refine As AWIN.RefineByGroup
Const token As String = "xxy"
Dim UA As AWIN.UserAuthentication = New AWIN.UserAuthentication
With UA
.sApiKey = token
End With
service.UserAuthenticationValue = UA
columns = New AWIN.getProductList
Dim stringsofthings As String() = {"sId", "iCategoryId", "iMerchantId", "sMerchantProductId", "iAdult", "bHotpick", _
"iUpc", "iEan", "sMpn", "iIsbn", "sName", "sDescription", "sSpecification", _
"sPromotion", "sBrand", "sModel", "sAwDeepLink", "sAwThumbUrl", "sAwImageUrl", _
"sMerchantThumbUrl", "sMerchantImageUrl", "sDeliveryTime", "fPrice", "sCurrency", _
"fStorePrice", "fRrpPrice", "fDeliveryCost", "bWebOffer", "bPreOrder", "sWarranty"}
columns.sColumnToReturn = stringsofthings
response = service.getProductList(columns)
For c = 0 To UBound(response.oProduct)
ReDim Preserve AWresults(c)
AWresults(c) = New AWIN.Product
AWresults(c) = response.oProduct(c)
Console.WriteLine(AWresults.ToString)
Next
Console.ReadLine()
End Sub

Related

VB.NET extract data from API

I am a beginner in VB.NET and i am trying to extract data from an API and add it to a listview column but i don't know how to extract the data.
[This is the API][1]
[1]: https://tmnf.exchange/api/tracks?author=lolsport&count=40&fields=TrackId%2CTrackName
It is a API for downloading race tracks for Trackmania.
The data is shown as follows {"TrackId":9707620,"TrackName":"lolsport R444"},
Now what i need is the TrackIDs and TrackNames.
i have two columns in my program where i want to sort them into like so.
**TrackID** **TrackName**
9707620 lolsport R444
How can i do this? i googled a lot about regular expressions but i cant seem to find anything that works.
Dim Data As String = "{""TrackId"":9707620,""TrackName"":""lolsport R444""}"
Dim dataaray() As String = Data.Split(",")
Dim dataval() As String
Dim fileloc As String = Environment.CurrentDirectory & "\Test.txt"
If Not File.Exists(fileloc) Then
File.Create(fileloc).Dispose()
Else
File.Delete(fileloc)
File.Create(fileloc).Dispose()
End If
Dim objwriter As New StreamWriter(fileloc, True)
Dim i As Int32 = 0
Dim val As String
objwriter.WriteLine("**TrackID** **TrackName**")
For Each rw As String In dataaray
dataval = rw.Split(":")
val += dataval(1).Replace("""", "").Replace("}", "") & vbTab
If i = 1 Then
objwriter.WriteLine(val.TrimEnd())
val = String.Empty
i = 0
End If
i += 1
Next
objwriter.Close()
objwriter.Dispose()

how to Insert all datagrid rows in one time to sql data?

i use this code in my project to save datagrid rows to sql database but it work if there is no more than one row ! because i want use it in (Sales invoice form)
What change do I need ?
' in datagrid this code save one row only
Dim SaveCmd1 As SqlCommand = Zsqlcon.CreateCommand()
SaveCmd1.CommandText = ("insert into InvoicesDbTb2(IteSName,IteSSizeUnit,IteSCont,IteSPri,IteSTotContPri,IteSTask,IteSTotlAmnt) values
(#IteSName,#IteSSizeUnit,#IteSCont,#IteSPri,#IteSTotContPri,#IteSTask,#IteSTotlAmnt)")
For i As Integer = 0 To SellingDGView.Rows.Count - 2
Dim unused = SaveCmd1.Parameters.AddWithValue("#IteSName", SellingDGView.Rows(i).Cells(0).Value.ToString())
Dim unused3 = SaveCmd1.Parameters.AddWithValue("#IteSSizeUnit", SellingDGView.Rows(i).Cells(1).Value.ToString())
Dim unused4 = SaveCmd1.Parameters.AddWithValue("#IteSCont", SellingDGView.Rows(i).Cells(2).Value.ToString())
Dim unused5 = SaveCmd1.Parameters.AddWithValue("#IteSPri", SellingDGView.Rows(i).Cells(3).Value.ToString())
Dim unused6 = SaveCmd1.Parameters.AddWithValue("#IteSTotContPri", SellingDGView.Rows(i).Cells(4).Value.ToString())
Dim unused7 = SaveCmd1.Parameters.AddWithValue("#IteSTask", SellingDGView.Rows(i).Cells(5).Value.ToString())
Dim unused8 = SaveCmd1.Parameters.AddWithValue("#IteSTotlAmnt", SellingDGView.Rows(i).Cells(6).Value.ToString())
Next
You need to include part of the sql command building inside the loop.
P.S, although I’m not going to check for them here, there are limits on how many parameters and how long the sql command text can b (~2000 and ~8k respectively).
' in datagrid this code save one row only
Dim SaveCmd1 As SqlCommand = Zsqlcon.CreateCommand()
Dim sb as new StringBuilder
Sb.appendLine("insert into InvoicesDbTb2(IteSName,IteSSizeUnit,IteSCont,IteSPri,IteSTotContPri,IteSTask,IteSTotlAmnt) values ")
For i As Integer = 0 To SellingDGView.Rows.Count - 2
Sb.appendLine($"(#IteSName{i},#IteSSizeUnit{i},#IteSCont{i},#IteSPri{i},#IteSTotContPri{i},#IteSTask{i},#IteSTotlAmnt{i}){if(I=SellingDGView.Rows.Count - 2,"",",")}")
Dim unused = SaveCmd1.Parameters.AddWithValue($"#IteSName{i}", SellingDGView.Rows(i).Cells(0).Value.ToString())
Dim unused3 = SaveCmd1.Parameters.AddWithValue($"#IteSSizeUnit{i}", SellingDGView.Rows(i).Cells(1).Value.ToString())
Dim unused4 = SaveCmd1.Parameters.AddWithValue($"#IteSCont{i}", SellingDGView.Rows(i).Cells(2).Value.ToString())
Dim unused5 = SaveCmd1.Parameters.AddWithValue($"#IteSPri{i}", SellingDGView.Rows(i).Cells(3).Value.ToString())
Dim unused6 = SaveCmd1.Parameters.AddWithValue($"#IteSTotContPri{i}", SellingDGView.Rows(i).Cells(4).Value.ToString())
Dim unused7 = SaveCmd1.Parameters.AddWithValue($"#IteSTask{i}", SellingDGView.Rows(i).Cells(5).Value.ToString())
Dim unused8 = SaveCmd1.Parameters.AddWithValue($"#IteSTotlAmnt{i}", SellingDGView.Rows(i).Cells(6).Value.ToString())
Next
SaveCmd1.CommandText= sb.ToString
Another way to solve your problem is to do the insert inside the loop. While this will be slightly slower, in practice the difference is going to be irrelevant at your scale. If it was relevant, your entire process would need to be changed drastically.
For i As Integer = 0 To SellingDGView.Rows.Count - 2
Dim sb as new StringBuilder
Sb.appendLine("insert into InvoicesDbTb2(IteSName,IteSSizeUnit,IteSCont,IteSPri,IteSTotContPri,IteSTask,IteSTotlAmnt) values ")
Sb.appendLine($"(#IteSName{i},#IteSSizeUnit{i},#IteSCont{i},#IteSPri{i},#IteSTotContPri{i},#IteSTask{i},#IteSTotlAmnt{i})")
Using SaveCmd1 = Zsqlcon.CreateCommand(Sb.ToString)
Dim unused = SaveCmd1.Parameters.AddWithValue($"#IteSName{i}", SellingDGView.Rows(i).Cells(0).Value.ToString())
Dim unused3 = SaveCmd1.Parameters.AddWithValue($"#IteSSizeUnit{i}", SellingDGView.Rows(i).Cells(1).Value.ToString())
Dim unused4 = SaveCmd1.Parameters.AddWithValue($"#IteSCont{i}", SellingDGView.Rows(i).Cells(2).Value.ToString())
Dim unused5 = SaveCmd1.Parameters.AddWithValue($"#IteSPri{i}", SellingDGView.Rows(i).Cells(3).Value.ToString())
Dim unused6 = SaveCmd1.Parameters.AddWithValue($"#IteSTotContPri{i}", SellingDGView.Rows(i).Cells(4).Value.ToString())
Dim unused7 = SaveCmd1.Parameters.AddWithValue($"#IteSTask{i}", SellingDGView.Rows(i).Cells(5).Value.ToString())
Dim unused8 = SaveCmd1.Parameters.AddWithValue($"#IteSTotlAmnt{i}", SellingDGView.Rows(i).Cells(6).Value.ToString())
SaveCmd1.ExecuteNonQuery()
End Using
Next
Keep you connection and command local to the method where they are used. These database objects may be used unmanaged resources which need to be released. Normally this is done in their .Dispose method. A Using...End Using block handles this for you even if there is an error.
Add the parameters once outside the loop. I had to guess at the datatypes. Check your database for the actual types and adjust the code accordingly. You will also have to adjust the values of the parameters in the loop. See the CInt, CDec, .ToString etc..
Only the values of the parameters change in the loop. You are not creating and adding the parameters over and over.
Private Sub OPCode()
Using Zsqlcon As New SqlConnection("Your connection string"),
SaveCmd1 As New SqlCommand("insert into InvoicesDbTb2(IteSName,IteSSizeUnit,IteSCont,IteSPri,IteSTotContPri,IteSTask,IteSTotlAmnt) values
(#IteSName,#IteSSizeUnit,#IteSCont,#IteSPri,#IteSTotContPri,#IteSTask,#IteSTotlAmnt)", Zsqlcon)
With SaveCmd1.Parameters
.Add("#IteSName", SqlDbType.NVarChar, 100)
.Add("#IteSSizeUnit", SqlDbType.Int)
.Add("#IteSCont", SqlDbType.Int, 100)
.Add("#IteSPri", SqlDbType.Decimal)
.Add("#IteSTotContPri", SqlDbType.Decimal)
.Add("#IteSTask", SqlDbType.NVarChar, 100)
.Add("#IteSTotlAmnt", SqlDbType.Decimal)
End With
Zsqlcon.Open()
For i As Integer = 0 To SellingDGView.Rows.Count - 2
With SaveCmd1
.Parameters("#IteSName").Value = SellingDGView.Rows(i).Cells(0).Value.ToString()
.Parameters("#IteSSizeUnit").Value = CInt(SellingDGView.Rows(i).Cells(1).Value)
.Parameters("#IteSCont").Value = CInt(SellingDGView.Rows(i).Cells(2).Value)
.Parameters("#IteSPri").Value = CDec(SellingDGView.Rows(i).Cells(3).Value)
.Parameters("#IteSTotContPri").Value = CDec(SellingDGView.Rows(i).Cells(4).Value)
.Parameters("#IteSTask").Value = SellingDGView.Rows(i).Cells(5).Value.ToString()
.Parameters("#IteSTotlAmnt").Value = CDec(SellingDGView.Rows(i).Cells(6).Value)
End With
SaveCmd1.ExecuteNonQuery()
Next
End Using
End Sub

Page redirected too many times ASP.NET

Dear StackOverflow community,
I am still new with ASP.NET and playing have been playing around and I've encountered an error to authenticate my login where it shows up an error like "Page redirected too many times" and it happen something that are keep looping and I can't figure it out after 2 days.
I've implemented my login using header.acsx so it can be a global authentication to all page.
Here is the code of head.vb:
If String.IsNullOrEmpty(Session(GetSessionKey("UserName"))) Then
Dim userName As String = HttpContext.Current.User.Identity.Name.Split("\")(1)
SessionInitialiser(userName)
End If
Response.Redirect("~/EventRegistration.aspx")
Page_Load function:
Dim adserv As New ActiveDirectory()
Dim userDetails As WebServiceUserPrincipal = adserv.Getuser(userName)
Dim userGroups As String() = adserv.GetUserGroups(userName)
Dim _dt As New DataTable
_dt.Columns.Add("Group")
For Each item As String In userGroups
Dim _row As DataRow = _dt.NewRow()
_row("Group") = item
_dt.Rows.Add(_row)
Next
Session(GetSessionKey("FullName")) = userDetails.DisplayName
Session(GetSessionKey("Groups")) = _dt
Session(GetSessionKey("UserName")) = userName
Session(GetSessionKey("Switch")) = "OK"
Dim filter_auditGroup As String = ConfigurationSettings.AppSettings("FILTER_GROUP")
Dim _adt As New DataTable
_adt.Columns.Add("Group")
For Each item As String In userGroups
If (item = filter_auditGroup) Then
Dim _row As DataRow = _adt.NewRow()
_row("Group") = item
_adt.Rows.Add(_row)
End If
Next
'If _adt.Rows.Count > 0 Then
' Session(GetSessionKey("AuditGroups")) = _adt
'End If
End Sub
Check Access Function
If Not IsPostBack Then
Dim arr As Array = Request.Url.AbsolutePath.Split("/")
Dim page As String = arr(arr.Length - 1).ToString().Split(".")(0) '-- Ballot.aspx, remove .aspx and get Ballot only
Dim signOut As New List(Of String)
signOut.Add("SwitchUser")
signOut.Add("SignOut")
If (Not signOut.Contains(page, StringComparer.OrdinalIgnoreCase)) Then
If (String.IsNullOrEmpty(Session(GetSessionKey("UserName")))) Then
Response.Redirect("~/Default.aspx")
Else
Dim group As DataTable = Session(GetSessionKey("Groups"))
'Dim auditGroup As DataTable = Session(GetSessionKey("AuditGroups"))
Dim adminPage As New List(Of String)
adminPage.Add("BallotProcess")
adminPage.Add("CodeTablePage")
adminPage.Add("MaintainBallotItem")
adminPage.Add("MaintainCodeItem")
adminPage.Add("MaintainItemDetail")
If (adminPage.Contains(page, StringComparer.OrdinalIgnoreCase) And Not CheckAdmin(group)) Then
Response.Redirect("~/EventRegistration.aspx")
End If
'If (page.Equals("AuditPage", StringComparison.OrdinalIgnoreCase) And Not CheckAudit(group)) Then
' Response.Redirect("~/default.aspx")
'End If
End If
End If
End If
Check Admin Function
Private Function CheckAdmin(ByVal group As DataTable) As Boolean
Dim i As Integer
If Not IsNothing(group) Then
For i = 0 To group.Rows.Count - 1
If group.Rows(i)(0) = ConfigurationSettings.AppSettings("FILTER_GROUP") Then
CheckAdmin = True
Session(GetSessionKey("EventAdmin")) = 1
Exit Function
End If
Next
End If
End Function
I have found my answer through countless of debug and all I need to fix this code is just move the Response.Redirect("~/EventRegistration.aspx") into the If Else statement above. This is because when the if else statement execute to get the identity, after its if else statement the value will be Nothing, then it redirect to the page while the page will try to get the identity and it execute again the if else countless of times..
If String.IsNullOrEmpty(Session(GetSessionKey("UserName"))) Then
Dim userName As String = HttpContext.Current.User.Identity.Name.Split("\")(1)
SessionInitialiser(userName)
Response.Redirect("~/EventRegistration.aspx")
End If

Google Calender Vr3 - How do I add a reminder to an event?

So far I am able to insert an event in a calendar using the following code.
Dim calService As CalendarService = calendarFunctions.getCalendarService(txtrefreshToken.Text.Trim)
Dim calEventEntry As New Data.Event
calEventEntry.Summary = "Invoice #123456 Due on dd/mm/yyyy"
calEventEntry.Description = "Client: Acme Printing Ltd."
calEventEntry.Id = "inv5670010"
Dim eventStartDT As New Data.EventDateTime()
eventStartDT.DateTime = DateTime.Now.AddHours(24)
Dim eventStartEndDT As New Data.EventDateTime()
eventStartEndDT.DateTime = DateTime.Now.AddHours(25)
calEventEntry.Start = eventStartDT
calEventEntry.End = eventStartEndDT
Dim er As New EventsResource(calService)
Dim erResp As Data.Event = er.Insert(calEventEntry, txtactiveCal.Text.Trim).Execute()
'SO FAR SO GOOD!
'Add email reminder to event
Dim remR As New EventReminder()
remR.Method = "email"
remR.Minutes = 10
erResp.Reminders.Overrides.Add(remR) ' <<< ERROR: Object reference not set to an instance of an object
In the last block I am trying to add the reminder to the event (I unserstand this must be done after the event has been created?) . On the last line I get the following error:
Object reference not set to an instance of an object
Does anyone know what I'm doing wrong here?
I would suspect Overrides to be null by default so you can't add anything in there unless you initialize them.
I solved this in the end by creating a List(of EventReminder) object adding the desired reminder and binding this to the Overrides property for event.reminders. Hopefully this code may be of help to others.
Dim eventReminder As New List(Of EventReminder)()
eventReminder.Add(New EventReminder() With { _
.Minutes = 10, _
.Method = "email" _
})
Dim de As New Data.Event.RemindersData()
de.UseDefault = False
de.[Overrides] = eventReminder
calEventEntry.Reminders = de
Dim er As New EventsResource(calService)
Dim erResp As Data.Event = er.Insert(calEventEntry, txtactiveCal.Text.Trim).Execute()
Response.Write("Event ID: " & erResp.Id & "<br/>")
Response.Write("Link: " & erResp.HtmlLink & "<br/>")

why I can't set nothing to variable in vb.net?

I have a a problem with my vb.net.
my code
class business{
buiding as string
}
I load data from mongodb
Dim collection1 = db1.GetCollection(Of business)("tablebusiness")
Dim list = collection1.Find(query1)
For Each abiz In list
Dim biztemp = abiz
biztemp.buiding = nothing '//// (but I get biztemp.building = "") why??
'biztemp.building = "" here
Next