Hi I am starting to learn VB.NET and I am little bit confused right now.
I want to create a connection string dynamically at run time.
I made a module for it and I want to call it everytime I need it.
And now I'm on my login page but I don't know how to call my module or it's not possible.Code:Imports System.Data.SqlClient
Module Module1
Public connection As SqlConnection
Public cmd As SqlCommand
Public rd As SqlDataReader
Sub con()
connection = New SqlConnection
cmd = New SqlCommand
connection.ConnectionString = "Server='" & My.Settings.SName & "';user='" & My.Settings.UName & "';password='" & My.Settings.Pword & "';database='" & My.Settings.DBName & "'"
'Dim connection As New SqlConnection("Server='" & My.Settings.SName & "';user='" & My.Settings.UName & "';password='" & My.Settings.Pword & "';database='" & My.Settings.DBName & "'")
End Sub
End Module
Here's my login code:
By the way I'm using sql server 2008.Code:Imports System.Data.SqlClient
Public Class LoginForm1
Private Sub OK_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles OK.Click
con()
connection.Open()
cmd.Connection = connection
cmd.CommandText = "SELECT * from tbl_login where username='" & txtusername.Text & " and password='" & txtpassword.Text & "'"
If rd.HasRows Then
Mainform.Show()
Else
MsgBox("Invalid Login credentials", MsgBoxStyle.Exclamation, "Failed!")
End If
End Sub
Thank you so much
