Argument not specified for parameter 'e' of 'Protected Sub TextBox1(sender As Object, e As System.EventArgs)' - webforms

Imports System.Data.OleDb
Imports System.Data
Partial Class _Default
Inherits System.Web.UI.Page
Protected Sub TextBox1(sender As Object, e As System.EventArgs) Handles TextBox1.TextChanged
Dim userid As String = TextBox1.Text
Dim params(1) As OleDbParameter
params(0) = New OleDbParameter("uid", TextBox1.Text)
params(1) = New OleDbParameter("up", TextBox2.Text)
Dim sql = "select * from user where userid=#uid and userpassword=#up"
Dim ds As DataSet = AccessHelper.ExecuteDataSet(sql, params)
If ds.Tables(0).Rows.Count = 1 Then
Session("userid") = TextBox1.Text
Else
Dim paramst(1) As OleDbParameter
paramst(0) = New OleDbParameter("tid", TextBox1.Text)
paramst(1) = New OleDbParameter("tp", TextBox2.Text)
Dim sqlt = "select * from teacher where teacherid=#tid and userpassword=#tp"
Dim dst As DataSet = AccessHelper.ExecuteDataSet(sqlt, paramst)
If dst.Tables(0).Rows.Count = 1 Then
Session("teacherid") = TextBox1.Text
End If
End If
End Sub
End Class
Can't really figure out why I get the errors (http://i.imgur.com/Zb2hBlo.png)
No idea what I'm doing really but it's a check to see if the login exists. Beforehand it was saying that textbox1/2 wasn't declared but now it's switched to this; either way it doesn't work and I don't know what to do.

Related

Combobox by any contain

i am trying to filter combobox by any contain but it not happening
Private Sub cboServicename()
Try
Dim myConnToAccess As OleDb.OleDbConnection = MyDBmodule()
myConnToAccess.Open()
Dim ds = New DataSet
Dim tables = ds.Tables
Dim da = New OleDb.OleDbDataAdapter("SELECT Distinct service_name from Services_Data ", myConnToAccess)
da.Fill(ds, "Services_Data")
Dim view1 As New DataView(tables(0))
With auditmodule_Servicename
.DataSource = ds.Tables("Services_Data")
.DisplayMember = "service_name"
.ValueMember = "service_code"
.SelectedIndex = 0
End With
Catch ex As Exception
End Try
End Sub

vb.net WMI query to string

I have a little issue with WMI query.
I have to check if a certain property exists in a WMI query instance, the code i have done is:
Imports System.Management
Imports System.Management.Instrumentation
Public Class Form1
Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click
Dim search_cpu As New ManagementObjectSearcher("SELECT * FROM Win32_Processor")
Dim info_cpu As ManagementObject '= Convert.ToUInt32("search_cpu")
Dim cpu_v As Integer
For Each info_cpu In search_cpu.Get()
If search_cpu.Get("caption") = True Then
cpu_v = "Caption"
Label1.Text = ("Name: " & info_cpu(cpu_v).ToString())
End If
Next
End Sub
End Class
Any help will be appreciated.
Thanks in advance
I managed to reproduce. The below code works allright for me and Label1 now displays:
Intel64 Family 6 Model 58 Stepping 9
Sub Main()
Dim search_cpu As New ManagementObjectSearcher("SELECT * FROM Win32_Processor")
Dim info_cpu As ManagementObject '= Convert.ToUInt32("search_cpu")
Dim caption As String
For Each info_cpu In search_cpu.Get()
caption = info_cpu("caption").ToString()
Next
Label1.Text = caption
if (string.isnullorempty(caption))
Label1.Text ="<does not exist>"
End Sub

Acces denied to registry on windows 8 for vb.net app

I created a small app in vb.net for a friend. The problem is that on my PC (W7 64bits) it works great (registry reading / writing) but on my friends PC (W8 64bits) it doesn't work.
It it strange but at the moment he runs my app (it checks the registry on loading) it gives him a "Access to registry denied" error. I tried to run it with admin rights but it doesn't work either.
Here is my code:
Imports Microsoft.Win32
Public Class Form1
Dim planned As Date
Private Sub DateTimePicker1_ValueChanged(sender As Object, e As EventArgs) Handles DateTimePicker1.ValueChanged
End Sub
Private Sub planifier_Click(sender As Object, e As EventArgs) Handles planifier_button.Click
Dim toExecute As String = String.Format("shutdown -s -f -t {0}", 100)
Dim currentDate = System.DateTime.Now
Dim futureDate = DateTimePicker1.Value
Dim difference = futureDate - currentDate
Console.Out.WriteLine(difference)
System.Diagnostics.Process.Start("shutdown", "-s -f -t " & Math.Round(difference.TotalSeconds))
Me.planned = futureDate
saveStgFile(futureDate)
setup()
End Sub
Private Sub Shutdown_Load(sender As Object, e As EventArgs) Handles MyBase.Load
Console.Out.WriteLine(Application.ProductName & " & " & Application.ExecutablePath)
getStgFile()
getPlanned()
setup()
Dim baseKey = RegistryKey.OpenBaseKey(RegistryHive.LocalMachine, RegistryView.Registry64)
Startup.Checked = baseKey.OpenSubKey("SOFTWARE\Microsoft\Windows\CurrentVersion\Run", True).GetValue(Application.ProductName).Equals(Application.ExecutablePath)
End Sub
Private Sub cancel_button_Click(sender As Object, e As EventArgs) Handles cancel_button.Click
System.Diagnostics.Process.Start("shutdown", "-a")
Me.planned = Nothing
saveStgFile(Nothing)
setup()
End Sub
Sub setup()
If Me.planned.Equals(Nothing) Then
cancel_button.Enabled = False
planifier_button.Enabled = True
planifier_button.Text = "Planifier"
Else
cancel_button.Enabled = True
planifier_button.Enabled = False
planifier_button.Text = Me.planned.TimeOfDay.ToString()
End If
End Sub
Function getPlanned() As TimeSpan
Dim stg As String = getStgFile()
Dim fileContent As String = My.Computer.FileSystem.ReadAllText(stg)
Dim timespan As Date
If fileContent = "none" Then
Me.planned = Nothing
ElseIf Date.TryParse(fileContent, timespan) Then
Me.planned = timespan
End If
Return (Me.planned - System.DateTime.Now)
End Function
Function getStgFile() As String
Dim stgFile = System.IO.Path.Combine(My.Computer.FileSystem.SpecialDirectories.MyDocuments, "AutoShutdown")
If My.Computer.FileSystem.DirectoryExists(stgFile) = False Then
FileSystem.MkDir(stgFile)
End If
stgFile = System.IO.Path.Combine(stgFile, "settings.ini")
If My.Computer.FileSystem.FileExists(stgFile) = False Then
My.Computer.FileSystem.WriteAllText(stgFile, "none", False)
End If
Return stgFile
End Function
Sub saveStgFile(planned As Date)
Dim stgFile As String = getStgFile()
Try
If (planned.Equals(Nothing)) Then
My.Computer.FileSystem.WriteAllText(stgFile, "none", False)
Else
My.Computer.FileSystem.WriteAllText(stgFile, planned.ToString(), False)
End If
Catch ex As Exception
Throw ex
End Try
End Sub
Private Sub Startup_CheckedChanged(sender As Object, e As EventArgs) Handles Startup.CheckedChanged
Dim baseKey = RegistryKey.OpenBaseKey(RegistryHive.LocalMachine, RegistryView.Registry64)
If Startup.Checked Then
baseKey.OpenSubKey("SOFTWARE\Microsoft\Windows\CurrentVersion\Run", True).SetValue(Application.ProductName, Application.ExecutablePath)
Console.Out.WriteLine("Add to startup")
Else
baseKey.OpenSubKey("SOFTWARE\Microsoft\Windows\CurrentVersion\Run", True).DeleteValue(Application.ProductName)
Console.Out.WriteLine("Remove from startup")
End If
End Sub
End Class

problem with .net windows service

have written a windows service. while the code worked for a simple form app, its not working in a windows service. here;s the code
Imports System.Text.RegularExpressions
Imports System.Net.Sockets
Imports System.Net
Imports System.IO
Public Class Service1
Public Shared Function CheckProxy(ByVal Proxy As String) As Boolean
Dim myWebRequest As HttpWebRequest = CType(WebRequest.Create("http://google.com"), HttpWebRequest)
myWebRequest.Proxy = New WebProxy(Proxy, False)
myWebRequest.Timeout = 10000
Try
Dim myWebResponse As HttpWebResponse = CType(myWebRequest.GetResponse(), HttpWebResponse)
Dim loResponseStream As StreamReader = New StreamReader(myWebResponse.GetResponseStream())
Return True
Catch ex As WebException
If (ex.Status = WebExceptionStatus.ConnectFailure) Then
End If
Return False
End Try
End Function
Protected Overrides Sub OnStart(ByVal args() As String)
System.IO.File.AppendAllText("C:\AuthorLog.txt",
"AuthorLogService has been started at " & Now.ToString())
MsgBox("1")
Timer1.Enabled = True
End Sub
Protected Overrides Sub OnStop()
' Add code here to perform any tear-down necessary to stop your service.
Timer1.Enabled = False
End Sub
Private Sub Timer1_Tick(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Timer1.Tick
MsgBox("2")
' Check if the the Event Log Exists
If Not Diagnostics.EventLog.SourceExists("Evoain Proxy Bot") Then
Diagnostics.EventLog.CreateEventSource("MyService", "Myservice Log") ' Create Log
End If
' Write to the Log
Diagnostics.EventLog.WriteEntry("MyService Log", "This is log on " & _
CStr(TimeOfDay), EventLogEntryType.Information)
Dim ProxyURLList As New Chilkat.CkString
Dim ProxyListPath As New Chilkat.CkString
Dim WorkingProxiesFileData As New Chilkat.CkString
Dim ProxyArray(10000000) As String
Dim event1 As New Chilkat.CkString
event1.setString("started")
event1.saveToFile("B:\serv.txt", "utf-8")
Dim ns As Integer = 0
'Read Configuration File
Dim sFileName As String
Dim srFileReader As System.IO.StreamReader
Dim sInputLine As String
sFileName = "config.ini"
srFileReader = System.IO.File.OpenText(sFileName)
sInputLine = srFileReader.ReadLine()
Dim temp As New Chilkat.CkString
Do Until sInputLine Is Nothing
temp.setString(sInputLine)
If temp.containsSubstring("proxyurllist=") = True Then
'Read Proxy-URL-List
ProxyURLList.setString(sInputLine)
If ProxyURLList.containsSubstring("proxyurllist=") = True Then
ProxyURLList.replaceFirstOccurance("proxyurllist=", "")
End If
ElseIf temp.containsSubstring("finalproxylistpath=") = True Then
'Read Proxy-List-Path
ProxyListPath.setString(sInputLine)
If ProxyListPath.containsSubstring("finalproxylistpath=") = True Then
ProxyListPath.replaceFirstOccurance("finalproxylistpath=", "")
End If
End If
sInputLine = srFileReader.ReadLine()
Loop
'*********Scrape URLs From Proxy-URL-List*********************
Dim ProxyURLFileData As New Chilkat.CkString
ProxyURLFileData.loadFile(ProxyURLList.getString, "utf-8")
Dim MultiLineString As String = ProxyURLFileData.getString
Dim ProxyURLArray() As String = MultiLineString.Split(Environment.NewLine.ToCharArray, System.StringSplitOptions.RemoveEmptyEntries)
Dim i As Integer
For i = 0 To ProxyURLArray.Count - 1
'********Scrape Proxies From Proxy URLs***********************
Dim http As New Chilkat.Http()
Dim success As Boolean
' Any string unlocks the component for the 1st 30-days.
success = http.UnlockComponent("Anything for 30-day trial")
If (success <> True) Then
Exit Sub
End If
' Send the HTTP GET and return the content in a string.
Dim html As String
html = http.QuickGetStr(ProxyURLArray(i))
Dim links As MatchCollection
links = Regex.Matches(html, "[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}:[0-9]{1,5}")
For Each match As Match In links
Dim matchUrl As String = match.Groups(0).Value
ProxyArray(ns) = matchUrl
ns = ns + 1
Next
Next
'*************CHECK URLs*****************
Dim cnt As Integer = 0
For cnt = 0 To 1
Dim ProxyStatus As Boolean = CheckProxy("http://" + ProxyArray(cnt) + "/")
If ProxyStatus = True Then
WorkingProxiesFileData.append(Environment.NewLine)
WorkingProxiesFileData.append(ProxyArray(cnt))
End If
Next
WorkingProxiesFileData.saveToFile(ProxyListPath.getString, "utf-8")
End Sub
End Class
what are the basic thing i cannot do in a windows service? oh, and i am using the chilkat library too..
why can't i use all of my code in OnStart? i did so and the services stops just as it starts.
can i use something else except a timer and put an endless loop?
Running as a windows service typically won't let you see any popup boxes, etc since there's no UI (Unless you check the box to allow interaction with the desktop).
Try adding a Timer1.Start in your OnStart method. Then in your Timer1_Tick method, first thing stop the timer, then at the end start it back up, this way your Tick method won't fire while you're already doing work.
I realize I'm (very) late to this party, but what kind of timer are you using? A System.Windows.Forms.Timer is designed for use in a single threaded Windows Form and will not work in a Windows Service app. Try a System.Timers.Timer instead.

Entity Framework problem with Anonymous type return and manipulation

so I am working with entity framework, I had written a function before with ado.net in it to fetch two values and return a datatable later to which I did some manipulation.
code is below
Protected Sub ddlFieldMappingProfile_SelectedIndexChanged(ByVal sender As Object, ByVal e As System.EventArgs) Handles ddlFieldMappingProfile.SelectedIndexChanged
If ddlFieldMappingProfile.SelectedValue >= 0 Then
btnImportData.Enabled = True
End If
If ddlFieldMappingProfile.SelectedValue <= 0 Then Return
Dim lstHeaders As List(Of String)
Dim dtMapping As New DataTable()
Dim intCount As Integer = 0
Try
Using com As New Common
With com
dtMapping = .getProfileFields(Convert.ToInt32(ddlFieldMappingProfile.SelectedValue))
IEMapping = .getProfileFields(Convert.ToInt32(ddlFieldMappingProfile.SelectedValue))
lstHeaders = .FileHeaders(FileUpl.FiletoRead, FileUpl.Delimiter)
End With
End Using
dtMapping.Columns.Add("MatchIndex")
For Each row As DataRow In dtMapping.Rows
For intCount = 0 To lstHeaders.Count() - 1
If lstHeaders(intCount) = row.Item("Dump_FieldName") Then
row.Item("MatchIndex") = intCount
Exit For
Else
row.Item("MatchIndex") = -1
End If
Next
Next
gdvFieldData.DataSource = dtMapping
gdvFieldData.DataBind()
gdvFieldData.Visible = True
Catch ex As Exception
Throw ex
Finally
dtMapping.Dispose()
lstHeaders = Nothing
End Try
End Sub
But now that I am using entity frame work I have written the LINQ query like
Dim Context As New ICOM_Model.IcomsEntities()
Dim query = From F In Context.Incentive_Prepaid_FieldMapping Where F.Profile_ID = Profile_ID
Select New With {.Activations_FieldName = F.Activations_FieldName, .Dump_FieldName = F.Dump_FieldName}
An anonymous type.
Please help me what is going to be the return type and how am I going to manipulate in the code for ddlFieldMappingProfile_SelectedIndexChanged
In your code return type will be anonymous with two property "Activations_FieldName and Dump_FieldName" and you can access that values by "query" object.
you can make a class with properties which you are selecting by entity and fill that class object.
class ABC{
string Activations_FieldName{get;set;}
string Dump_FieldName{get;set;}
}
Dim Context As New ICOM_Model.IcomsEntities()
List<ABC> query = From F In Context.Incentive_Prepaid_FieldMapping Where F.Profile_ID = Profile_ID
Select New ABC With {.Activations_FieldName = F.Activations_FieldName, .Dump_FieldName = F.Dump_FieldName}
Now you can use this class object in your code. hope this help.

Resources