Sei sulla pagina 1di 3

Logon Authentication program

Public Class Login Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click Dim connection As New SqlClient.SqlConnection Dim command As New SqlClient.SqlCommand Dim adaptor As New SqlClient.SqlDataAdapter Dim dataset As New DataSet connection.ConnectionString = ("Data Source=.\SQLEXPRESS;AttachDbFilename=|DataDirectory|\HMS.mdf;Integrated Security=True;User Instance=True") command.CommandText = "SELECT * FROM [login] WHERE eid= '" & TextBox1.Text & "' AND password= '" & MaskedTextBox1.Text & "';" connection.Open() command.Connection = connection adaptor.SelectCommand = command adaptor.Fill(dataset, "0") Dim count = dataset.Tables(0).Rows.Count If count > 0 Then Solution.Show() Me.Hide() Else MsgBox("Incorrect login", MsgBoxStyle.Critical) TextBox1.Clear() MaskedTextBox1.Clear() End If End Sub End Class

ERR: An error has occurred while establishing a connection to the server. When connecting to SQL Server 2005, this failure may be caused by the fact that under the default settings SQL Server does not allow remote connections. (provider: SQL Network Interfaces, error: 26 - Error Locating Server/Instance Specified)

Data insert

Imports System.Data.SqlClient

Public Class PA Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click Dim conn As New SqlClient.SqlConnection Dim cmd As New SqlClient.SqlCommand conn.ConnectionString = ("Data Source=NIDSRV;Initial Catalog=hmis;Integrated Security=True;Pooling=False") cmd.Connection = conn conn.Open() cmd.CommandText = "INSERT INTO regist (salutation,surname,firstname,guardian,relation,dob,gender,genderf,address,nationality,pi n,contact,age,generate) VALUES ('" & ComboBox1.Text & "','" & TextBox1.Text & "','" & TextBox2.Text & "','" & TextBox3.Text & "','" & ComboBox2.Text & "','" & TextBox4.Text & "','" & RadioButton1.Text & "','" & RadioButton2.Text & "','" & TextBox5.Text & "','" & ComboBox3.Text & "','" & TextBox6.Text & "','" & TextBox7.Text & "','" & Label11.Text & "','" & TextBox8.Text & "')" Try cmd.ExecuteNonQuery() Catch ex As System.Data.SqlClient.SqlException MsgBox(ex.Message) End Try conn.Close() MsgBox("Success") autogenerate_id() End Sub Private Sub autogenerate_id() Dim conn As New SqlClient.SqlConnection Dim cmd As New SqlClient.SqlCommand conn.ConnectionString = ("Data Source=NIDSRV;Initial Catalog=hmis;Integrated Security=True;Pooling=False") cmd.Connection = conn conn.Open() Dim number As Integer cmd.CommandText = "SELECT Max(generate) FROM regist" If IsDBNull(cmd.ExecuteScalar) Then number = 1 TextBox8.Text = number Else number = cmd.ExecuteScalar + 1 TextBox8.Text = number End If cmd.Dispose() conn.Close() conn.Dispose() End Sub Private Sub TextBox8_TextChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles TextBox8.TextChanged autogenerate_id() End Sub End Class

*****************************************************************************************

RadioButton data insert


Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click Dim conn As New SqlClient.SqlConnection Dim cmd As New SqlClient.SqlCommand Dim adaptor As New SqlClient.SqlDataAdapter Dim gender As String If RadioButton1.Checked Then gender = "Male" Else gender = "Female" End If conn.ConnectionString = ("Data Source=NIDSRV;Initial Catalog=hmis;Integrated Security=True;Pooling=False") cmd.Connection = conn cmd.CommandText = "INSERT INTO new.dbo.gendermf VALUES ('" & RadioButton1.Text & "')" Try conn.Open() cmd.ExecuteNonQuery() MessageBox.Show("Successfully Completed") 'this will clear your controls when the form is saved RadioButton2.Checked = False RadioButton1.Checked = False

Catch ex As Exception MessageBox.Show(ex.Message) Finally conn.Close() End Try

@saluBox,@surBox,@fnBox,@gBox,@rBox,@paBox,@pinBox,@dtpicker,@agelbl,@RadioButton1,@RadioButton2,@natio nBox,@contactBox,@genBox

if (RadioButton1.Checked) cmd.Parameters.AddWithValue("@gender", "Male"); else cmd.Parameters.AddWithValue("@gender", "Female"); cmd.ExecuteNonQuery(); MessageBox.Show("Inserted");

Potrebbero piacerti anche