|
****This is my component coding****
Public Class DepartmentValidator
Inherits System.ComponentModel.Component
Private empid As String
Private pwd As String
Public Property EmployeeID() As String
Get
Return empid
End Get
Set(ByVal Employeeid As String)
empid = Employeeid
End Set
End Property
Public Property Password() As String
Get
Return pwd
End Get
Set(ByVal Password As String)
pwd = Password
End Set
End Property
Public Function Validate() As Boolean
Dim em As String
Dim pw As String
Dim conn As New OleDb.OleDbConnection("provider=SQLOLEDB;User ID=saassword=;Trusted_Connection=yes;Initial Catalog=employees;data source=localhost")
Try
conn.Open()
Catch ex As Exception
MsgBox("There have problem in connecting to database")
End Try
Dim selectemp As OleDb.OleDbCommand = New OleDb.OleDbCommand("select cempid,cpassword from employees where cEmpID=?", conn)
Dim dr As OleDb.OleDbDataReader
dr = selectemp.ExecuteReader()
Do While dr.Read = True
em = dr.GetString(0)
pw = dr.GetString(12)
If (em = empid And pw = pwd) Then
Return True
Else
Return False
End If
Loop
dr.Close()
*****This is user validation form coding***
Private Sub btnok_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnok.Click
Dim validator As DepartmentValidator
validator = New DepartmentValidator
validator.EmployeeID = txtempid.Text
validator.Password = txtpwd.Text
validator.Validate()
If validator.Validate = True Then
MsgBox("Valid User")
Else
MsgBox("Invalid user")
End If
when i'm run this and type employee id and password there display the error in my component codings. Error is like below
An unhandled exception of type 'System.InvalidOperationException' occurred in system.data.dll
Additional information: ExecuteReader requires an open and available Connection. The connection's current state is Closed.
Could someone help solve 4 this problem pls,if need my coding also ask frm me
Thank You
-- modified at 1:06 Wednesday 26th July, 2006
|
|
|
|
|
maybe Youre connection String isn't True
Check you're Connection string
MHf
|
|
|
|
|
hi
i have virtually no vb experience so i hope i can explain this clearly.
i have made a interface that i wont to copy a players name from a server browser listview "the all seeing eye"
i need a textbox to autofill with the players name from a listview once i start inputting a name.
getting the textbox to autofill from the name listview is not happining.
can anybody help me with this.
the reason i am undertaking this is to help us adminasta a game server which is being overrun with game hackers.
i wont to be able to copy a players name and paste in a guid search engine to determine if they have any hacking convictions listed against them.
cheers
toe
-- modified at 1:43 Friday 28th July, 2006
|
|
|
|
|
Textboxes do not support autofill, you will need to find or write a custom control to do this.
Christian Graus - Microsoft MVP - C++
Metal Musings - Rex and my new metal blog
|
|
|
|
|
vb2005 text and combobox's do autofill but gettin them to fill from another program is the problem.
in the controls properties down the bottom u have all the autocomplete properties
cheers
toe
|
|
|
|
|
bump
|
|
|
|
|
How can i enumerate tray icon? I want to get other program' tray icon
|
|
|
|
|
I need some help creating an MS-Word counter macro as I'm not well versed in Visual Basic. I am trying to find a repeating XML tag pattern in an MS-Word file as shown below:
<subunit>
any text . . .
</subunit>
What I need the macro to do is to attach a number to the tag and each time the tag is found, the number should increment by 1.
See my desired output:
<subunit_1>
any text . . .
</subunit_1>
<p>
<subunit_2>
any text . . .
</subunit_2>
<p>
<subunit_3>
any text . . .
</subunit_3>
Can such a macro be created in Word? I do have some experience editing macros in the VB editor but very limited.
I might add that I already have a macro that duplicates an XML tag each time I run the macro but without the incrementing. Should I try to edit this current macro to get my desired output?
Thanks
Harold
-- modified at 0:05 Wednesday 26th July, 2006
|
|
|
|
|
Hi,
My application requires a date/time field to be set to display a blank field by default, unless modified by the user. Right now it displays the current date and, if not changed by the user, on saving the record that date is passed to the database. Could somebody please let me know how this is done?
Thanks in advance.
Larry
|
|
|
|
|
Hi
Whats the control you are using in the user interface?
Chandra
|
|
|
|
|
I have one last VB.NET newbie question for the masses and then I promise to make my way.
I have a list box with myriad entries and I would like to know when the user right-clicks a specific item in the list box so I can display a right-click menu with a couple options they can perform on that entry. How is this done in VB.NET?
Thank you!
|
|
|
|
|
You will need to add a context menu to the form.
<br />
Private Sub ListBox1_MouseDown(ByVal sender As Object, ByVal e As System.Windows.Forms.MouseEventArgs) Handles ListBox1.MouseDown<br />
If e.Button = MouseButtons.Right Then<br />
ContextMenu1.Show(Me.ListBox1, New System.Drawing.Point(e.X, e.Y))<br />
End If<br />
End Sub<br />
Mike Lasseter
|
|
|
|
|
I wrote a scipt that takes an Access database and imports it to SQL Server. The Access db has over 1 million records in it. The script works, but around halfway through adding the records I get a "page cannot be displayed" error. It is strange because there is nothing in my script that tells it to change pages. This error occurs during the WHILE loop. If i look at my SQL db, i can see that the script is still running and adding records even though this error page appears. I think it may be some sort of server setting, but have not been able to figure it out. I need to redirect the user later in the script after this import completes, so I need to get this fixed. Here is my code:
<br />
Sub Cat1_Import()<br />
Dim startTime = Timer<br />
Dim AccessConn As OleDbConnection<br />
Dim AccessCmd As OleDbCommand<br />
Dim RecSet As OleDbDataReader<br />
Dim SqlString As String = "Data Source=mysource;Initial Catalog=mycatalog;Pooling=True;Min Pool Size=100;Max Pool Size=200;User ID=user;Password=pass"<br />
Dim SqlConn As SqlConnection<br />
Dim SqlCmd As SqlCommand<br />
Dim SqlRecSet As SqlDataReader<br />
Dim UpdateSql As String<br />
Dim SelectSql As String = "SELECT * FROM [Equipment Contract Pricing]"<br />
<br />
'connect to Access db<br />
AccessConn = New OleDbConnection("Provider=Microsoft.Jet.OLEDB.4.0;data source=path-to-my-db\Equipment.mdb")<br />
AccessConn.Open()<br />
AccessCmd = New OleDbCommand("SELECT * FROM [Equipment Contract Pricing]", AccessConn)<br />
RecSet = AccessCmd.ExecuteReader()<br />
<br />
'connect to sql server<br />
SqlConn = New SqlConnection(SqlString)<br />
SqlConn.Open()<br />
<br />
'loop through access db records to insert each record into Sql Server db<br />
While RecSet.Read()<br />
UpdateSql = "INSERT INTO [Equipment Contract Pricing] (CLIN, Offeror_ID, Product, ID_Number, Description, Specifications, Standards, ISO9000, Manufacturer, Model_No, Cat_Code, Sale_Area, Purch_Price, Price_Unit, YR, Last_Update_P) Values "<br />
UpdateSql &= "('" & RecSet("CLIN") & "', '" & RecSet("Offeror_ID") & "', '" & Replace(RecSet("Product"), "'", "''") & "', '" & RecSet("ID_Number") & "', '" & Replace(RecSet("Description"), "'", "''") & "', '" & Replace(RecSet("Specifications"), "'", "''") & "', '" & RecSet("Standards") & "', '" & RecSet("ISO9000") & "'"<br />
UpdateSql &= ", '" & RecSet("Manufacturer") & "', '" & RecSet("Model_No") & "', '" & RecSet("Cat_Code") & "', '" & RecSet("Sale_Area") & "', convert(money,'" & RecSet("Purch_Price") & "'), '" & RecSet("Price_Unit") & "', '" & RecSet("YR") & "', '" & RecSet("Last_Update_P") & "')"<br />
SqlCmd = New SqlCommand(UpdateSql, SqlConn)<br />
SqlCmd.ExecuteNonQuery()<br />
End While<br />
<br />
SqlCmd = New SqlCommand(SelectSql, SqlConn)<br />
SqlRecSet = SqlCmd.ExecuteReader()<br />
If SqlRecSet.HasRows Then<br />
Session("import") = "Data successfully transferred."<br />
Else<br />
Session("import") = "Temporary table is still empty. There was an error importing the data."<br />
End If<br />
<br />
RecSet.Close()<br />
SqlRecSet.Close()<br />
AccessConn.Close()<br />
SqlConn.Close()<br />
<br />
Dim endTime, processTime, hrTime, minTime, secTime As Double<br />
endTime = Timer<br />
processTime = endTime - startTime<br />
hrTime = processTime / 3600<br />
minTime = processTime / 60<br />
secTime = Decimal.Remainder(processTime, 60)<br />
If secTime < 0 Then secTime = 0<br />
Session("time") = "Total Process Time: " & FormatNumber(hrTime, 0) & " hours, " & FormatNumber(minTime, 0) & " minutes, " & FormatNumber(secTime, 0) & " seconds"<br />
<br />
End Sub<br />
Anyone have any iseas why this is happening?
Thanks,
Mike
|
|
|
|
|
I just wanted to add to this post. I put a timer on the page and this error occurs at the 1 hour mark every time. I am pretty sure this is a server issue. Maybe there is a setting in IIS I am overlooking. Any ideas?
|
|
|
|
|
Hello!
I posted a bit ago with a question about a syntax error in a seemingly-flawless SQL string but now I'm back with what is hopefully a simpler problem:
In my program, record (tuples) in a database are represented as items in a list box. The user can select any item they wish from the list box and have all the information about that entry readily displayed to the form - this part is working just fine.
What isn't working is record deletion. Although the deletion itself is working (in that it does, in fact, delete the selected record), it does not update the primary key (an ID # in this case) at all thus after deleting a few random records I am left with a rather unorderly database.
I have tried manually updating the ID via an SQL UPDATE statement as follows:
oleCommand.CommandText = "UPDATE tblEvents (ID) VALUES (" + nCount + ")"
Where:
oleCommand = my OleDbCommand object
tblEvents = my table within the database I'm using
ID = the primary key of this table
nCount = a counter variable dually-used to step through a loop while setting the ID for each record.
Please let me know if oyu have any ideas and thank you in advance!
|
|
|
|
|
Hi
Is the ID field an AutoNumber?
|
|
|
|
|
I have tried both Autonumber as well as a regular Number and neither work. Currently, it is set for Autonumber
|
|
|
|
|
Hi
Is the SQL statement within the loop?
Chandra
|
|
|
|
|
The following is the entire event handler for btnDelete_Click:
Private Sub btnDelete_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnDeleteSelected.Click
Dim strSQL As String = ""
Dim nIndex As Integer = 0
Dim nCount As Integer = 0
If lstHistory.SelectedIndex < 0 Then
MsgBox("You must first select the record you wish to delete.", MsgBoxStyle.Critical, "Selection Required")
Else
nIndex = lstHistory.SelectedIndex
lstHistory.ClearSelected()
strSQL = "DELETE FROM tblEvents WHERE ID = " + nIndex.ToString()
Try
oleCommand = New OleDbCommand()
With oleCommand
.Connection = New OleDbConnection(strConn)
.Connection.Open()
.CommandText = strSQL
End With
oleDataAdapter = New OleDb.OleDbDataAdapter(oleCommand)
oleCommand.ExecuteNonQuery()
oleCommand.Connection.Close()
PopulateHistory()
Catch ex As Exception
MsgBox(ex.Message)
End Try
Try
oleCommand = New OleDbCommand()
oleCommand.Connection = New OleDbConnection(strConn)
oleCommand.Connection.Open()
For nCount = 0 To nRecords
oleCommand.CommandText = "UPDATE tblEvents (ID) VALUES (" + nCount + ")"
oleDataAdapter = New OleDbDataAdapter(oleCommand)
Next
oleCommand.Connection.Close()
Catch ex As Exception
MsgBox(ex.Message)
End Try
End If
End Sub
The UPDATE SQL string is, indeed, within a For loop. I update the ID VALUE of that string with the counter (nCount) of the For loop in attempt to manually update each tuple's ID.
-- modified at 16:32 Tuesday 25th July, 2006
|
|
|
|
|
Hi
I think the SQL statement that you have used for the Update command should read:
"Update tblEvents set Id = " & nCount
Another thing - this is going to try to set the ID of all records in the table, you should specify a "where " clause, that identifies a unique record to be updated.
hth
Chandra
|
|
|
|
|
I'm trying to populate a drop down list from an arraylist.
I have an array called idnums
thought I could do something like this:
Dim C As Integer
Dim I As Integer
C = idnums.Count
For I = 0 To C
dlIdNums.Items.Add(idnums.Item(I))
Next
thanks
|
|
|
|
|
Are you taking about a ComboBox or ASP.NET Control DropDownList
No need for the Loop Just bind the Datasource to the arraylist.
dlIdNums.DataSource = idnums
dlIdNums.DisplayMember = "name" or DataTextField(ASP)
dlIdNums.ValueMember = "value" or DataValueField(ASP)
Check Help if I am wrong it is in there.
|
|
|
|
|
I have a datagrid control, but i dont know how to tell when a user clicks on one of the rows and how to know which row he clicked on!
Can somebody please tell me how to do this.
There are 10 types of people in this world, those who understand binary and those who don't!
|
|
|
|
|
Hi,
How can i acces to allocation table of NTFS disks in .net?
ANd after, i need to write directly to the non-allocated spaces?
Thanx,
Cesur
|
|
|
|
|
have a vb6 program that handle a database file ( access) and i need to save that file to a cd (compact disk) to use it with another program (i.e. to transfer the file from computer to another computer ) and i want to make that by click a "save" command button in my vb6 program
|
|
|
|