So I have a button that Scrapes Proxies from Public Websites and adds the proxies to a Listbox but there's an issue, It for some reason shows the Proxies in the Listbox once its Actually finished doing all the "For Each"'s.
It even doesn't show a Progress Bar until everything is Finished which is making it pointless.
Screenshot of what I mean:
(As you can see it only shows the Progress Bar when its finished rather then while its Scraping.)
Is there any workaround for this?
My Code:
Imports System.Text.RegularExpressions
Public Class Form1
Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click
Button1.Enabled = False
ScrapeProgress.Visible = True
'Set the Time;
Dim time = TimeOfDay.ToString("h:mm:ss tt")
'Sources;
Dim sources(122) As String
sources(0) = "http://proxy-ip-list.com"
sources(1) = "http://fineproxy.org/eng/?p=6#more-6"
sources(2) = "http://aliveproxy.com/high-anonymity-proxy-list"
sources(3) = "http://aliveproxy.com/anonymous-proxy-list/"
sources(4) = "http://aliveproxy.com/transparent-proxy-list"
sources(5) = "http://aliveproxy.com/socks5-list"
sources(6) = "http://aliveproxy.com/socks4-list"
sources(7) = "http://aliveproxy.com/fastest-proxies/"
sources(8) = "http://atomintersoft.com/anonymous_proxy_list"
sources(9) = "http://atomintersoft.com/high_anonymity_elite_proxy_list"
sources(10) = "http://atomintersoft.com/proxy_list_domain"
sources(11) = "http://atomintersoft.com/proxy_list_port"
sources(12) = "http://atomintersoft.com/transparent_proxy_list"
sources(13) = "http://atomintersoft.com/products/alive-proxy/socks5-list"
sources(14) = "http://best-proxy.com/english/search.php?search=anonymous-and-elite&country=any&type=anonymous-and-elite&port=any&ssl=any"
sources(15) = "http://best-proxy.com/english/search.php?search=anonymous-and-elite&country=any&type=anonymous-and-elite&port=any&ssl=any&p=2"
sources(16) = "http://best-proxy.com/english/search.php?search=anonymous-and-elite&country=any&type=anonymous-and-elite&port=any&ssl=any&p=3"
sources(17) = "http://www.samair.ru/proxy/socks01.htm"
sources(18) = "http://www.samair.ru/proxy/socks02.htm"
sources(19) = "http://www.samair.ru/proxy/socks03.htm"
sources(20) = "http://www.samair.ru/proxy/socks04.htm"
sources(21) = "http://www.samair.ru/proxy/socks05.htm"
sources(22) = "http://www.samair.ru/proxy/proxy-01.htm"
sources(23) = "http://www.samair.ru/proxy/proxy-02.htm"
sources(24) = "http://www.samair.ru/proxy/proxy-03.htm"
sources(25) = "http://www.samair.ru/proxy/proxy-04.htm"
sources(26) = "http://www.samair.ru/proxy/proxy-05.htm"
sources(27) = "http://www.samair.ru/proxy/proxy-06.htm"
sources(28) = "http://www.samair.ru/proxy/proxy-07.htm"
sources(29) = "http://www.samair.ru/proxy/proxy-08.htm"
sources(30) = "http://www.samair.ru/proxy/proxy-09.htm"
sources(31) = "http://www.samair.ru/proxy/proxy-10.htm"
sources(32) = "http://www.samair.ru/proxy/proxy-11.htm"
sources(33) = "http://www.samair.ru/proxy/proxy-12.htm"
sources(34) = "http://www.samair.ru/proxy/proxy-13.htm"
sources(35) = "http://www.samair.ru/proxy/proxy-14.htm"
sources(36) = "http://www.samair.ru/proxy/proxy-15.htm"
sources(37) = "http://www.samair.ru/proxy/proxy-16.htm"
sources(38) = "http://www.samair.ru/proxy/proxy-17.htm"
sources(39) = "http://www.samair.ru/proxy/proxy-18.htm"
sources(40) = "http://www.samair.ru/proxy/proxy-19.htm"
sources(41) = "http://www.samair.ru/proxy/proxy-20.htm"
sources(42) = "http://www.samair.ru/proxy/proxy-21.htm"
sources(43) = "http://www.samair.ru/proxy/proxy-22.htm"
sources(44) = "http://www.samair.ru/proxy/proxy-23.htm"
sources(45) = "http://www.samair.ru/proxy/proxy-24.htm"
sources(46) = "http://www.samair.ru/proxy/proxy-25.htm"
sources(47) = "http://www.samair.ru/proxy/proxy-26.htm"
sources(48) = "http://www.samair.ru/proxy/proxy-27.htm"
sources(49) = "http://www.samair.ru/proxy/proxy-28.htm"
sources(50) = "http://www.samair.ru/proxy/proxy-29.htm"
sources(51) = "http://www.samair.ru/proxy/proxy-30.htm"
sources(52) = "http://nntime.com/proxy-list-01.htm"
sources(53) = "http://nntime.com/proxy-list-02.htm"
sources(54) = "http://nntime.com/proxy-list-03.htm"
sources(55) = "http://nntime.com/proxy-list-04.htm"
sources(56) = "http://nntime.com/proxy-list-05.htm"
sources(57) = "http://nntime.com/proxy-list-06.htm"
sources(58) = "http://nntime.com/proxy-list-07.htm"
sources(59) = "http://nntime.com/proxy-list-08.htm"
sources(60) = "http://nntime.com/proxy-list-09.htm"
sources(61) = "http://nntime.com/proxy-list-10.htm"
sources(62) = "http://nntime.com/proxy-list-11.htm"
sources(63) = "http://nntime.com/proxy-list-12.htm"
sources(64) = "http://nntime.com/proxy-list-13.htm"
sources(65) = "http://nntime.com/proxy-list-14.htm"
sources(66) = "http://nntime.com/proxy-list-15.htm"
sources(67) = "http://nntime.com/proxy-list-16.htm"
sources(68) = "http://nntime.com/proxy-list-17.htm"
sources(69) = "http://nntime.com/proxy-list-18.htm"
sources(70) = "http://nntime.com/proxy-list-19.htm"
sources(71) = "http://nntime.com/proxy-list-20.htm"
sources(72) = "http://nntime.com/proxy-list-21.htm"
sources(73) = "http://nntime.com/proxy-list-22.htm"
sources(74) = "http://nntime.com/proxy-list-23.htm"
sources(75) = "http://nntime.com/proxy-list-24.htm"
sources(76) = "http://nntime.com/proxy-list-25.htm"
sources(77) = "http://nntime.com/proxy-list-26.htm"
sources(78) = "http://nntime.com/proxy-list-27.htm"
sources(79) = "http://nntime.com/proxy-list-28.htm"
sources(80) = "http://nntime.com/proxy-list-29.htm"
sources(81) = "http://nntime.com/proxy-list-30.htm"
sources(82) = "http://proxylistchecker.org/proxylists.php?t=&p=1"
sources(83) = "http://proxylistchecker.org/proxylists.php?t=&p=2"
sources(84) = "http://proxylistchecker.org/proxylists.php?t=&p=3"
sources(85) = "http://proxylistchecker.org/proxylists.php?t=&p=4"
sources(86) = "http://proxylistchecker.org/proxylists.php?t=&p=5"
sources(87) = "http://proxylistchecker.org/proxylists.php?t=&p=6"
sources(88) = "http://proxylistchecker.org/proxylists.php?t=&p=7"
sources(89) = "http://proxylistchecker.org/proxylists.php?t=&p=8"
sources(90) = "http://proxylistchecker.org/proxylists.php?t=&p=9"
sources(91) = "http://proxylistchecker.org/proxylists.php?t=&p=10"
sources(92) = "http://proxylistchecker.org/proxylists.php?t=&p=11"
sources(93) = "http://proxylistchecker.org/proxylists.php?t=&p=12"
sources(94) = "http://proxylistchecker.org/proxylists.php?t=&p=13"
sources(95) = "http://proxylistchecker.org/proxylists.php?t=&p=14"
sources(96) = "http://proxylistchecker.org/proxylists.php?t=&p=15"
sources(97) = "http://txt.proxyspy.net/proxy.txt"
sources(98) = "http://www.getproxy.jp/en/default/1"
sources(99) = "http://www.getproxy.jp/en/default/2"
sources(100) = "http://www.getproxy.jp/en/default/3"
sources(101) = "http://www.getproxy.jp/en/default/4"
sources(102) = "http://www.getproxy.jp/en/default/5"
sources(103) = "http://www.ip-adress.com/proxy_list/?k=time&d=desc"
sources(104) = "http://www.my-proxy.com/free-proxy-list.html"
sources(105) = "http://www.my-proxy.com/free-proxy-list-2.html"
sources(106) = "http://www.my-proxy.com/free-proxy-list-3.html"
sources(107) = "http://www.my-proxy.com/free-proxy-list-4.html"
sources(108) = "http://www.my-proxy.com/free-proxy-list-5.html"
sources(109) = "http://www.my-proxy.com/free-proxy-list-6.html"
sources(110) = "http://www.my-proxy.com/free-proxy-list-7.html"
sources(111) = "http://www.my-proxy.com/free-proxy-list-8.html"
sources(112) = "http://www.my-proxy.com/free-proxy-list-9.html"
sources(113) = "http://www.my-proxy.com/free-proxy-list-10.html"
sources(114) = "http://sslproxies24.blogspot.com/feeds/posts/default"
sources(115) = "http://proxyserverlist-24.blogspot.com/feeds/posts/default"
sources(116) = "http://newfreshproxies24.blogspot.com/feeds/posts/default"
sources(117) = "http://socksproxylist24.blogspot.com/feeds/posts/default"
sources(118) = "http://vip-socks24.blogspot.com/feeds/posts/default"
sources(119) = "http://irc-proxies24.blogspot.com/feeds/posts/default"
sources(120) = "http://www.socks24.org/feeds/posts/default"
sources(121) = "http://www.getproxy.jp/en/"
sources(122) = "http://www.getproxy.jp/en/fastest"
'Add the Copyright Holder to the top of the List;
ListBox1.Items.Add("Proxies Scraped using a Test Build Program by ShinyMK")
'Foreach Source, Do the following Code;
For Each element As String In sources
'Set the Status Label to "Scraping";
ToolStripStatusLabel3.Text = "Scraping"
'Connect to the Proxy Source;
Dim source As Net.HttpWebRequest = Net.WebRequest.Create(element)
Try
'Prepare the Response;
Dim response As Net.HttpWebResponse = source.GetResponse
'Load the HTML;
Dim reader As IO.StreamReader = New IO.StreamReader(response.GetResponseStream())
Dim html As String = reader.ReadToEnd
'Regex;
Dim expression As New Regex("[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}:[0-9]{1,4}")
'Set the Matches variable to the Matched Sections of the HTML source;
Dim matches As MatchCollection = expression.Matches(html)
'Add the proxies to the ListBox;
For Each proxy As Match In matches
'If the ListBox doesn't already contain the Proxy, Add It;
If Not ListBox1.Items.Contains(proxy.ToString) Then
'Add the Proxy;
ListBox1.Items.Add(proxy.ToString)
'Add 1 to the "Count" label's value;
ToolStripStatusLabel5.Text += 1
End If
Next
'Add the Time and Success message for each Successful Scraped Source;
ListBox2.Items.Add("[" + time + "] Success: " + element)
Catch ex As Exception
ListBox2.Items.Add("[" + time + "] ERROR Scraping from " + element + " - " + ex.Message)
End Try
Next
'Re-Enable the Button and set the Status Lable to "Idle";
Button1.Enabled = True
ToolStripStatusLabel3.Text = "Idle"
End Sub
Private Sub Button2_Click(sender As Object, e As EventArgs) Handles Button2.Click
If ListBox1.Items.Count = (0) Then
MessageBox.Show("No Proxies Scraped.", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error)
Else
'defining a streamwriter
Dim S_W As IO.StreamWriter
'converting listbox items to string
Dim itms() As String = {ListBox1.Items.ToString}
''defining a savefiledialog
Dim save As New SaveFileDialog
Dim it As Integer
save.FileName = "SSLPro.xyz " + TimeOfDay.ToString("h.mm.ss tt")
save.Filter = "Text (*.txt)|*.txt|All Files (*.*)|*.*"
save.CheckPathExists = True
save.ShowDialog(Me)
S_W = New IO.StreamWriter(save.FileName)
For it = 0 To ListBox1.Items.Count - 1
S_W.WriteLine(ListBox1.Items.Item(it))
Next
S_W.Close()
End If
End Sub
Private Sub Button3_Click(sender As Object, e As EventArgs) Handles Button3.Click
ListBox1.Items.Clear()
ListBox2.Items.Clear()
ToolStripStatusLabel5.Text = "0"
End Sub
End Class
To allow your UI thread to refresh and show the information while you’re iterating through the proxies you need to use a separate thread to do the job.
You can use the .NET control Backgroundworker to do this. With this control you can start a thread to do the job and this thread can inform the UI thread of the state of the operation using the events of the Brackgroundworker, then the UI thread can update the UI accordingly.
Here you can find some examples of how to use a backgroundworker.
A basic sample of this could be something like:
Imports System.ComponentModel
Public Class Form1
Private ListOfProcessedElements as List(of integer)
Private Sub backgroundWorker1_DoWork(ByVal sender As System.Object,ByVal e As DoWorkEventArgs) Handles backgroundWorker1.DoWork
'Here you do your worker
'Add an element to the list of Processed elements
ListOfProcessedElements.add(ANY_NUMBER)
worker.ReportProgress(i * 10)
End Sub
' This event handler updates the progress.
Private Sub backgroundWorker1_ProgressChanged(ByVal sender As System.Object, ByVal e As ProgressChangedEventArgs) Handles backgroundWorker1.ProgressChanged
'Here you can access to the shared variable ListOfProcessedElements and do whatever you want in the UI
End Sub
' This event handler deals with the results of the background operation.
Private Sub backgroundWorker1_RunWorkerCompleted(ByVal sender As System.Object, ByVal e As RunWorkerCompletedEventArgs) Handles backgroundWorker1.RunWorkerCompleted
End Sub
End Class
Related
I want to check if the current file exists at the same time save video to different file but it only overwrites to an existing file.
Here is my code:
Private Sub ButtonVIDEO_Click(ByVal sender As System.Object, e As System.EventArgs) Handles ButtonVIDEO.Click
f = New Filters
cap = New Capture(f.VideoInputDevices(0), f.AudioInputDevices(0))
cap.PreviewWindow = PictureBox1
Dim Filename As String = "c:\\folder\MyFile"
Dim i As Integer = 0
Dim extension As String = ".mp4"
If ButtonVIDEO.BackColor = Color.Black Then
cap.Filename = Filename + extension
If File.Exists(Filename) Then
Do
i = i + 1
Loop While File.Exists(Filename + i.ToString() + extension)
Filename = Filename + i.ToString()
End If
cap.Cue()
cap.Start()
ButtonVIDEO.BackColor = Color.Red
ButtonVIDEO.Text = "PLAYING"
ButtonPHOTO.Hide()
End If
End Sub
You are assigning the file name to cap before searching for an unsused file name.
Also, there is an error in your logic, as you are creating the full file name with Filename + i.ToString() + extension but you also append i to Filename itself with Filename = Filename + i.ToString().
So, in then end, you are appending the number twice.
Private Sub ButtonVIDEO_Click(ByVal sender As System.Object, e As System.EventArgs) _
Handles ButtonVIDEO.Click
Dim Filename As String = "c:\folder\MyFile"
Dim i As Integer = 0
Dim extension As String = ".mp4"
Dim path As String = Filename & extension
f = New Filters
cap = New Capture(f.VideoInputDevices(0), f.AudioInputDevices(0))
cap.PreviewWindow = PictureBox1
If ButtonVIDEO.BackColor = Color.Black Then
If File.Exists(path) Then
Do
i = i + 1
path = Filename & i & extension
Loop While File.Exists(path)
End If
cap.Filename = path
cap.Cue()
cap.Start()
ButtonVIDEO.BackColor = Color.Red
ButtonVIDEO.Text = "PLAYING"
ButtonPHOTO.Hide()
End If
End Sub
The path should have only one backslash in c:\folder. In VB strings are concatenated with &, not +.
See answer to The difference between + and & for joining strings in VB.NET
So I created a spotify checker to check a list of accounts on their logins and current subscription, This works fine, but it's only running on one thread and that in my opinion is really slow. So I started searching around for multithreading (I am pretty new to vb.net and am trying to learn this way.) But everything I threw at it would just run all threads seperately on the same accounts without any difference in results, just that they were printed out multiple times.
The code for the sub Login:
Public Sub Login()
Dim index As Integer = 0
While index < Combos.Count
Dim str() As String = Combos(index).Split(":")
Using req As New HttpRequest
req.UserAgent = Http.ChromeUserAgent
req.Cookies = New CookieDictionary()
req.Proxy = Nothing
req.IgnoreProtocolErrors = True
req.Get("https://accounts.spotify.com/en-US/login?continue=https:%2F%2Fwww.spotify.com%2Fus%2Faccount%2Foverview%2F")
Dim token As String = req.Cookies.ToString
Dim csrf As String = Regex.Match(token, "csrf_token=(\S+)").Groups(1).ToString
req.Referer = "https://accounts.spotify.com/en-US/login?continue=https:%2F%2Fwww.spotify.com%2Fus%2Faccount%2Foverview%2F"
req.AddHeader("Cookie", "csrf_token=" + csrf + "; __bon=MHwwfDQ1MzY4Nzk4M3wxOTA1NDg5NTI4NnwxfDF8MXwx; fb_continue=https%3A%2F%2Fwww.spotify.com%2Fus%2Faccount%2Foverview%2F; remember=false")
req.AddParam("remember", "false")
req.AddParam("username", str(0))
req.AddParam("password", str(1))
req.AddParam("captcha_token", "")
req.AddParam("csrf_token", csrf)
Dim respo As String = req.Post("https://accounts.spotify.com/api/login").ToString
If respo.Contains("displayName") Then
Dim IT As New ListViewItem
IT.Text = str(0)
IT.SubItems.Add(str(1))
Dim html As String = req.Post("https://spotify.com/account/subscription/").ToString
Dim Info As Match = Regex.Match(html, "<h3.*>(.*)<\/h3>")
Dim Type As String = Info.Groups(1).Value
If Type.Contains("Spotify Premium") Then
IT.SubItems.Add("Spotify Premium")
ListView1.Items.Add(IT)
Label3.Text += 1
Label1.Text += 1
ElseIf Type.Contains("Premium for Family") Then
IT.SubItems.Add("Spotify Premium for Family")
ListView1.Items.Add(IT)
Label3.Text += 1
Label1.Text += 1
Else
If StrafeCheckBox1.Checked = False Then
Label2.Text += 1
Else
IT.SubItems.Add("Free")
ListView1.Items.Add(IT)
Label1.Text += 1
End If
End If
Else
Label2.Text += 1
End If
End Using
index += 1
StrafeProgressBar1.Value = index
If index = Combos.Count Then
MsgBox("Done, successfull logins: " + Label1.Text)
End If
End While
End Sub
Code for the start button:
Private Sub LoginBTN_Click(sender As Object, e As EventArgs) Handles StartBTN.Click
Dim IH As New Thread(AddressOf Login) : IH.Start()
StrafeProgressBar1.Maximum = Combos.Count
End Sub
So what I basically want to know, is how I get the threads to split the
workload evenly. and finish the job a lot quicker.
All help is appreciated.
Basically I generate a random word for example
"Tree" and when I press the T button it changes the label into a T but then when I choose R it doesnt show, can someone else see what i've done wrong?
here is my code
Sub GuessLetter(ByVal LetterGuess As String)
Dim strGuessedSoFar As String = Lbltempword.Text
Dim LengthOfSecretWord As Integer
LengthOfSecretWord = secret.Length - 1
tempWord = ""
Dim letterPosition As Integer
For letterPosition = 0 To LengthOfSecretWord
If secret.Substring(letterPosition, 1) = LetterGuess Then
tempWord = tempWord & LetterGuess
Else
tempWord = tempWord & Lbltempword.Text.Substring(letterPosition, 1)
End If
Next
Lbltempword.Text = tempWord
If Lbltempword.Text = secret Then 'YOU WIN
DisableButtons()
BtnStart.Enabled = True
MsgBox("YOU WIN")
End If
If Lbltempword.Text = strGuessedSoFar Then
NumWrong = NumWrong + 1
End If
DisplayHangman(NumWrong)
End Sub
Private Sub btnStart_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles BtnStart.Click
randomword()
MsgBox(secret)
EnableButtons()
BtnStart.Enabled = False
'Load up the temp word label with dashes
Secret_Word = secret
LoadLabelDisplay()
NumWrong = 0
DisplayHangman(NumWrong)
End Sub
Sub LoadLabelDisplay()
Lbltempword.Text = ""
Dim LengthOfSecretWord As Integer
LengthOfSecretWord = secret.Length - 1
Dim LetterPosition As Integer
For LetterPosition = 0 To LengthOfSecretWord
Lbltempword.Text = Lbltempword.Text & "-"
Next
End Sub
I also generate the random words by doing this.
Sub randomword()
Dim RAND(16)
Dim rng As New System.Random()
For i = 0 To 16
RAND(0) = "Tree"
RAND(1) = "Star"
RAND(2) = "Jesus"
RAND(3) = "Present"
RAND(4) = "advent"
RAND(5) = "Calender"
RAND(6) = "Jinglebell"
RAND(7) = "skint"
RAND(8) = "lapland"
RAND(9) = "Santa"
RAND(10) = "raindeer"
RAND(11) = "Cookies"
RAND(12) = "Milk"
RAND(13) = "nothing"
RAND(14) = "play"
RAND(15) = "sack"
Next
secret = RAND(rng.Next(RAND.Count()))
End Sub
in my code the data is saving if no.of days to complete=0.I want it should not happen
in my code a msg comes "time to complete and time to acknowledged can be only be posiitve" but still data saves.i dont want it to be saved !!
Protected Sub btnSubmit_Click(sender As Object, e As EventArgs) Handles btnSubmit.Click
Try
Dim i As Integer
If gvBanckmark.Rows.Count > 0 Then
For i = 0 To gvBanckmark.Rows.Count - 1
Dim lblBenchMarkID As Label = CType(gvBanckmark.Rows(i).FindControl("lblBenchMarkID"), Label)
Dim lblSubCategoryId As Label = CType(gvBanckmark.Rows(i).FindControl("lblSubCategoryId"), Label)
Dim ddlFrequencyTypeAcknowledge As DropDownList = CType(gvBanckmark.Rows(i).FindControl("ddlFrequencyTypeAcknowledge"), DropDownList)
Dim ddlFrequencyTypeComplete As DropDownList = CType(gvBanckmark.Rows(i).FindControl("ddlFrequencyTypeComplete"), DropDownList)
Dim txtTimeToAcknowledge As TextBox = CType(gvBanckmark.Rows(i).FindControl("txtTimeToAcknowledge"), TextBox)
Dim txtTimeToComplete As TextBox = CType(gvBanckmark.Rows(i).FindControl("txtTimeToComplete"), TextBox)
Dim objBenchMark As BO.BenchMark = New BO.BenchMark()
objBenchMark.BuildingID = Convert.ToInt32(ddlBuilding.SelectedValue)
objBenchMark.CategoryID = Convert.ToInt32(ddlCategory.SelectedValue)
objBenchMark.SubCategoryID = Convert.ToInt32(lblSubCategoryId.Text.ToString())
objBenchMark.FrequencyTypeToAcknowledge = ddlFrequencyTypeAcknowledge.SelectedValue.ToString()
objBenchMark.FrequencyTypeToComplete = ddlFrequencyTypeComplete.SelectedValue.ToString()
objBenchMark.TimeToAcknowledge = Convert.ToInt32(txtTimeToAcknowledge.Text.ToString())
objBenchMark.TimeToComplete = Convert.ToInt32(txtTimeToComplete.Text.ToString())
If lblBenchMarkID.Text.ToString() = 0 Then
objBenchMark.BenchMarkID = 0
objBenchMark.CreateByUserId = UserWrapper.GetCurrentUser().ContactID
BO.BenchMark.InsertBechMarkData(objBenchMark)
Else
objBenchMark.BenchMarkID = Convert.ToInt32(lblBenchMarkID.Text.ToString())
objBenchMark.ModifiedByUserId = UserWrapper.GetCurrentUser().ContactID
BO.BenchMark.UpdateBechMarkData(objBenchMark)
End If
Next i
End If
lblError.Visible = True
lblError.Text = "<a cssClass=""messageGood"">Benchmark data has been saved sucessfully.</a>"
Catch ex As Exception
lblError.Text = ex.Message
lblError.Visible = True
End Try
End Sub
Your data is not being saved, but the message telling you the data has been saved is being presented, despite it's saved or not.
Move thses lines inside the if-end if:
lblError.Visible = True
lblError.Text = "<a cssClass=""messageGood"">Benchmark data has been saved sucessfully.</a>"
Im making a silverlight 5 application and im using RIA WCS services to connect to sql, i can add data,delete data, edit data, and get all data, but the problem is that i need to retrieve a specific record not the whole entity, when i try the following code just nothing happens:
Private Sub Button1_Click(sender As System.Object, e As System.Windows.RoutedEventArgs) Handles Button1.Click
' InitializeComponent()
objctx = New BanksDomainContext
Dim itemType = Branch_NameComboBox.SelectedItem.GetType
Dim pi = itemType.GetProperty(Branch_NameComboBox.DisplayMemberPath)
Dim cbi = pi.GetValue(Branch_NameComboBox.SelectedItem, Nothing).ToString()
Dim BranchName As String = cbi
' Dim query As EntityQuery(Of Branches) = objctx.GetBranchesDetailsQuery(BranchName)
' Dim loadOp As LoadOperation(Of Branches) = Me.objctx.Load(query)
' DataGrid1.ItemsSource = loadOp.Entities
' objctx.Load(query, LoadData, Nothing)
Dim loadOp = Me.objctx.Load(Me.objctx.GetBranchesDetailsQuery(BranchName))
LoadData(loadOp)
End Sub
Private Sub LoadData(lo As LoadOperation)
For Each br As Branches In lo.Entities
AddressTextBlock.Text = br.Address
CoordinatesTextBlock.Text = br.Coordinates
ManagerTextBlock.Text = br.Manager
PhoneTextBlock.Text = br.Phone
FaxTextBlock.Text = br.Fax
Next
End Sub
can someone guide me on how to do it?
The following is the solution to load text boxes from SQL records by selecting the search term from a list box:
Private Sub Branch_NameComboBox_SelectionChanged(sender As System.Object, e As System.Windows.Controls.SelectionChangedEventArgs) Handles Branch_NameComboBox.SelectionChanged
m_PushpinLayer.Children.Clear()
objctx = New BanksDomain
Dim itemType = Branch_NameComboBox.SelectedItem.[GetType]()
Dim pi = itemType.GetProperty(Branch_NameComboBox.DisplayMemberPath)
Dim cbi = pi.GetValue(Branch_NameComboBox.SelectedItem, Nothing).ToString()
Dim BranchName As String = cbi
Dim itemType2 = NameComboBox.SelectedItem.[GetType]()
Dim pi2 = itemType2.GetProperty(NameComboBox.DisplayMemberPath)
Dim cbi2 = pi2.GetValue(NameComboBox.SelectedItem, Nothing).ToString()
Dim BankName As String = cbi2
Dim bb As EntityQuery(Of Branches) = From b In objctx.GetBranchesDetailsQuery(BranchName) Where b.Bank = BankName Select b
Dim res As LoadOperation(Of Branches) = objctx.Load(bb, New Action(Of LoadOperation(Of Branches))(AddressOf GetBeansCompleted), True)
End Sub
Private Sub GetBeansCompleted(args As LoadOperation(Of Branches))
For Each bc As Branches In args.Entities
'
Dim Latitude As Double = bc.Lat
Dim Longitude As Double = bc.Lon
Dim CoO As Location = New Location
CoO.Latitude = Decimal.Parse(Latitude)
CoO.Longitude = Decimal.Parse(Longitude)
Dim BName As String = bc.Branch_Name.ToString
Dim MKColor As Color = GetThisColor(bc.MapKeyColor.ToString)
AddPushPin(BName, CoO, MKColor)
AddressTextBlock.Text = (bc.Address.ToString)
LatTextBlock.Text = (Decimal.Parse(Latitude))
LonTextBlock.Text = (Convert.ToDecimal(Longitude))
ManagerTextBlock.Text = (bc.Manager.ToString)
PhoneTextBlock.Text = (bc.Phone.ToString)
FaxTextBlock.Text = (bc.Fax.ToString)
Next
End Sub