jibber4568
New member
- Joined
- May 17, 2008
- Messages
- 1
- Programming Experience
- 1-3
Hi there, was hoping someone might be able to help me out with something.
I have a windows form that contatins a login. Users enter their details and if they match the database entry they are told that login was successfull and taken to another form.
The next form contains a number of buttons that perform calulations and input the results into another database.
The problem is that whilst i can get the results into the database i would also like the username to.
I have read a bit on global variables and using modules but i just don't get what i am supposed to do to pass the variable into the module in the first place.
This is what i have for my login
The form refered to as "Trig" contains buttons that call the following class. It is within this class that i need to pass the username in order to add it to the database along with function used and date. Any help is much appreciated.
Cheers
I have a windows form that contatins a login. Users enter their details and if they match the database entry they are told that login was successfull and taken to another form.
The next form contains a number of buttons that perform calulations and input the results into another database.
The problem is that whilst i can get the results into the database i would also like the username to.
I have read a bit on global variables and using modules but i just don't get what i am supposed to do to pass the variable into the module in the first place.
This is what i have for my login
VB.NET:
Public Class LoginForm1
Private Sub OK_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles OK.Click
Dim logincheck As New login()
Dim username As String
Dim password As String
Dim DataContent As String
username = CType(UsernameTextBox.Text, String)
password = CType(PasswordTextBox.Text, String)
DataContent = logincheck.Login(username, password)
End Sub
Private Sub Register_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Register.Click
Dim Register As New Register
Register.Show()
End Sub
End Class
VB.NET:
Imports System.Data
Imports System.Data.SqlClient
Public Class login
Dim strconn, strSQL As String
Public Function Login(ByVal username As String, ByVal password As String)
strconn = "Data Source=.\SQLExpress;" & _
"Initial Catalog=NORTHWIND;Integrated Security=True;"
Using con As New SqlConnection(strconn)
con.Open()
Dim cmd As SqlCommand = New SqlCommand
cmd.CommandText = "select count(*) from TrigUsers where username ='" & username & "' and password = '" & Password & "'"
cmd.Connection = con
Dim i As String = cmd.ExecuteScalar
If i = "0" Then
Register.Show()
Else
MsgBox("Logged in")
Trig.Show()
End If
End Using
End Function
End Class
The form refered to as "Trig" contains buttons that call the following class. It is within this class that i need to pass the username in order to add it to the database along with function used and date. Any help is much appreciated.
Cheers
VB.NET:
Imports System.Data
Imports System.Data.SqlClient
Public Class adddet
Dim strconn, strSQL As String
Public Function adddetails(ByVal FunctionUsed As String, ByVal Today As String)
strconn = "Data Source=.\SQLExpress;" & _
"Initial Catalog=NORTHWIND;Integrated Security=True;"
strSQL = "INSERT INTO TrigData (Username, FunctionUsed, Date) VALUES ('" & username & "','" & FunctionUsed & "', '" & Today & "')"
Dim recordsInserted As Integer
Using cn As New SqlConnection(strconn)
Try
Dim command As New SqlCommand(strSQL, cn)
cn.Open()
recordsInserted = command.ExecuteNonQuery()
Catch ex As Exception
Return recordsInserted
End Try
End Using
End Function
End Class