Documenti di Didattica
Documenti di Professioni
Documenti di Cultura
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
*****************************************************************************************
@saluBox,@surBox,@fnBox,@gBox,@rBox,@paBox,@pinBox,@dtpicker,@agelbl,@RadioButton1,@RadioButton2,@natio nBox,@contactBox,@genBox