How to create a login form in VB (vs 2010) with ms sql server management studio [on hold]
I am new with VB. I got now the Visual Studio 2010. I've never used it before. I need the following:
I need a login form, which is using an ms sql server database, in which I stored usernames and passwords.
The DB name is saqib.
It contains students name table.
In the table I have 4 columns, first is Studentid, second is Firstname,third is LastName, the last is Email.
It contains just 5 datas.
5 answers
Add a reference to System.Data in your project so you are able to use the SqlConnection..
Then something like this might get you started. :)
Imports System.Data.SqlClient
Public Class Form1
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
Dim connetionString As String
Dim sqlCnn As SqlConnection
Dim sqlCmd As SqlCommand
Dim sql As String
connetionString = "Data Source=ServerName;Initial Catalog=DatabaseName;User ID=UserName;Password=Password"
sql = "SELECT column1, column2, etc FROM tablename"
sqlCnn = New SqlConnection(connetionString)
Try
sqlCnn.Open()
sqlCmd = New SqlCommand(sql, sqlCnn)
Dim sqlReader As SqlDataReader = sqlCmd.ExecuteReader()
While sqlReader.Read()
MsgBox(sqlReader.Item(0) & " - " & sqlReader.Item(1) & " - " & sqlReader.Item(2))
End While
sqlReader.Close()
sqlCmd.Dispose()
sqlCnn.Close()
Catch ex As Exception
MsgBox("Can not open connection ! ")
End Try
End Sub
End Class
Good luck! And let us know your progress! :)
@John Hanker: Where and How I can add Reference. data in project? i mean where i place this code?
In the solution explorer (the project treeview) in visual studio, there is a folder called references. Right click that folder and select add reference from the menu.
Oh, it's a web project! My fault. There's no References folder there.
Instead, right click the project name in solution explorer (the item selected in your submitted screenshot) and select add reference in the menu.