hi i just want my form to connect to a database. and also i want my password in my textbox to be encrpted .
i want it to check in the database if password and user = true then display next form and the login form should be close whenever i get the next form. need help plzzzzzz

man,its simple task-
dont worry,just create textbox& in properties make textmode-has password.to check whether name exists or not in password
private sub btn_check(sender,object)
Dim str As String = "select ID from table1 where ID = '" & txtid.Text & "'"
Dim con As String = ConfigurationManager.AppSettings("preeconn")
Dim com As New SqlCommand(str, New SqlConnection(con))
com.Connection.Open()
'Dim ds As New DataSet
Dim da As New SqlDataAdapter(str, con)
'dataadapter is used to populate(or fill) dataset with data .we use fill method....
Dim dr As SqlDataReader
'da.Fill(ds, "table1")
dr = com.ExecuteReader 'where sqldatareader ain't run without using sqlcommand
'executereader,executenonquery are methods of sqlcommand....
'hasrows,fieldcount...are methods of datareader....
If Not dr.Read() Then
label4.Text = "id doesnt exists"
Else
label4.Text = "id exists"
End If
End Sub

hi
the ConfigurationManager.AppSettings is not working in my visual basic 2005. can u help me . it tells me that i have to declare it ..... Help Plz

i think you just need to add reference to System.configuration.dll

I tried create login form with following code:
Code
Dim str As String = "SELECT [userID], [passid] FROM user WHERE [userid]='" & txtUsername.Text & "' and [passid] = '" & txtPassword.Text & "'"
Dim con As String = ConfigurationManager.AppSettings("preeconn")
Dim com As New SqlClient.SqlCommand(Str, New SqlClient.SqlConnection(con))
com.Connection.Open()
'Dim ds As New DataSet
Dim da As New SqlClient.SqlDataAdapter(Str, con)
'dataadapter is used to populate(or fill) dataset with data .we use fill method....
Dim dr As SqlClient.SqlDataReader
'da.Fill(ds, "table1")
dr = com.ExecuteReader 'where sqldatareader ain't run without using sqlcommand
'executereader,executenonquery are methods of sqlcommand....
'hasrows,fieldcount...are methods of datareader....
If Not dr.Read() Then
MessageBox.Show("Invalid user name, try again!", "Invalid Info")
'label4.Text = "id doesnt exists"
Else
Form2.Show()
'label4.Text = "id exists"
End If

It show error Invalidoperationexception was unhandled "The connectionstring property has not been initialized.

Please advice me. I try create login form more then 1 month. I need it very urgent.

It is not clear to me that you have actually added a connection string to the app.config file. Be sure that the application settings parameter "preecon" has a valid DB connection string as it's value. The following is a sample of a SQL Server connection string in a local app.config file; I am not sure what an Access connection string would look like.

<configuration>
<appSettings>
<add key="preecon" value="server=HOSTNAME;database=DBNAME;Security=SSPI"/>
</appSettings>
</configuration>

Cheers,

BD

bonjour ,j'ai un probrélém avec la connexion vb.net en sql server :
oConn = New SqlConnection()
Try

oConn.ConnectionString = "server=localhost" & SQL_Server & ";database=C:\Documents and Settings\Administrateur\Mes documents\Visual Studio 2008\Projects\Application\Application\P9.sdf" & SQL_Base & ";trusted_connection=true"

oConn.Open()

myCommand = New SqlCommand("INSERT INTO Personne " & "('" + T1.Text + "','" + T2.Text + "','" + T3.Text + "','" + T4.Text + "','" + T5.Text + "','" + T6.Text + "','" + T7.Text + "','" + T8.Text + "')")
MsgBox("Ajout reussie")

Catch err As Exception
MsgBox("Il y a eu une erreur de connection (SQL_Reader) : " + err.Message)
Finally
oConn.Close()
oConn = Nothing

End Try

Imports System.Data.OleDb

Public Class login1
Dim con As OleDbConnection
Dim da As OleDbDataAdapter
Dim cb As OleDbCommand
Dim ds As DataSet
Dim dr As OleDbDataReader
Dim i As Integer = 0
Dim addflag As Boolean = False

Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
cb = New OleDbCommand("select * from log", con)
dr = cb.ExecuteReader()
Dim unm, pwd As String
While dr.Read
unm = dr(0)
pwd = dr(1)
If TextBox1.Text.Equals(unm) And TextBox2.Text.Equals(pwd) Then
Module1.s = unm
End If
End While
TextBox1.Text = ""
TextBox2.Text = ""
MsgBox("Invalid User")
End Sub
end class

Imports System.Data.OleDb
Public Class Form1
Dim con As OleDbConnection
Dim da As OleDbDataAdapter
Dim cb As OleDbCommandBuilder
Dim ds As DataSet
Dim dr As DataRow
Dim i As Integer = 0
Dim addflag As Boolean = False

Private Sub Form1_FormClosed(ByVal sender As Object, ByVal e As System.Windows.Forms.FormClosedEventArgs) Handles Me.FormClosed
da.Update(ds, "emp")
End Sub
Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
'TODO: This line of code loads data into the 'PractDataSet.emp' table. You can move, or remove it, as needed.
Me.EmpTableAdapter.Fill(Me.PractDataSet.emp)
con = New OleDbConnection("provider=microsoft.jet.oledb.4.0; data source=d:\pract.mdb")
da = New OleDbDataAdapter("select * from emp", con)
cb = New OleDbCommandBuilder(da)
ds = New DataSet
da.Fill(ds, "emp")
End Sub
Sub dispdata()
TextBox1.Text = dr(0)
TextBox2.Text = dr(1)
TextBox3.Text = dr(2)
End Sub

Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
i = 0
dr = ds.Tables("emp").Rows(i)
dispdata()
End Sub

Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button2.Click
If i = 0 Then
MsgBox("First Record")
Else
i = i - 1
dr = ds.Tables("emp").Rows(i)
dispdata()
End If
End Sub

Private Sub Button3_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button3.Click
If i = ds.Tables("emp").Rows.Count - 1 Then
MsgBox("Last Record")
Else
i = i + 1
dr = ds.Tables("emp").Rows(i)
dispdata()
End If
End Sub

Private Sub Button4_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button4.Click
i = ds.Tables("emp").Rows.Count - 1
dr = ds.Tables("emp").Rows(i)
dispdata()
End Sub

Private Sub Button5_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button5.Click
If Button5.Text = "Add" Then
TextBox1.Text = ""
TextBox2.Text = ""
TextBox3.Text = ""
addflag = True
Button5.Text = "Save"
Button6.Text = "Cancel"
Else
If addflag = True Then
dr = ds.Tables("emp").NewRow
dr(0) = TextBox1.Text
dr(1) = TextBox2.Text
dr(2) = TextBox2.Text
ds.Tables("emp").Rows.Add(dr)
da.Update(ds, "emp")
addflag = False
Else
dr(0) = TextBox1.Text
dr(1) = TextBox2.Text
dr(2) = TextBox2.Text
da.Update(ds, "emp")
End If
Button5.Text = "Add"
Button6.Text = "Edit"
MsgBox("Saved Record")
End If
End Sub

Private Sub Button6_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button6.Click
If Button6.Text = "Edit" Then
Button5.Text = "Save"
Button6.Text = "Cancel"
addflag = False
Else
dispdata()
Button5.Text = "Add"
Button6.Text = "Edit"
End If
End Sub

Private Sub Button7_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button7.Click
If MessageBox.Show("Are you sure?", "confirmation", MessageBoxButtons.YesNo) = Windows.Forms.DialogResult.Yes Then
ds.Tables("emp").Rows(i).Delete()
If i = ds.Tables("emp").Rows.Count - 1 Then
i = i - 1
End If
da.Update(ds, "emp")
dr = ds.Tables("emp").Rows(i)
dispdata()
End If
End Sub

Private Sub Button8_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button8.Click
Me.Close()
End Sub
End Class


from shivpuje.deepali@gmail.com

This has been so helpful to me

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.