⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 form2.vb

📁 VB与ACCESS数据库制作的的注册登陆查询系统
💻 VB
📖 第 1 页 / 共 2 页
字号:
        Me.SqlDataAdapter1.SelectCommand = Me.SqlSelectCommand1
        Me.SqlDataAdapter1.TableMappings.AddRange(New System.Data.Common.DataTableMapping() {New System.Data.Common.DataTableMapping("Table", "yonghu", New System.Data.Common.DataColumnMapping() {New System.Data.Common.DataColumnMapping("name", "name"), New System.Data.Common.DataColumnMapping("age", "age"), New System.Data.Common.DataColumnMapping("class", "class"), New System.Data.Common.DataColumnMapping("xuehao", "xuehao")})})
        Me.SqlDataAdapter1.UpdateCommand = Me.SqlUpdateCommand1
        '
        'SqlDeleteCommand1
        '
        Me.SqlDeleteCommand1.CommandText = resources.GetString("SqlDeleteCommand1.CommandText")
        Me.SqlDeleteCommand1.Connection = Me.SqlConnection1
        Me.SqlDeleteCommand1.Parameters.AddRange(New System.Data.SqlClient.SqlParameter() {New System.Data.SqlClient.SqlParameter("@Original_xuehao", System.Data.SqlDbType.VarChar, 10, System.Data.ParameterDirection.Input, False, CType(0, Byte), CType(0, Byte), "xuehao", System.Data.DataRowVersion.Original, Nothing), New System.Data.SqlClient.SqlParameter("@Original_age", System.Data.SqlDbType.VarChar, 10, System.Data.ParameterDirection.Input, False, CType(0, Byte), CType(0, Byte), "age", System.Data.DataRowVersion.Original, Nothing), New System.Data.SqlClient.SqlParameter("@Original_class", System.Data.SqlDbType.VarChar, 10, System.Data.ParameterDirection.Input, False, CType(0, Byte), CType(0, Byte), "class", System.Data.DataRowVersion.Original, Nothing), New System.Data.SqlClient.SqlParameter("@Original_name", System.Data.SqlDbType.VarChar, 10, System.Data.ParameterDirection.Input, False, CType(0, Byte), CType(0, Byte), "name", System.Data.DataRowVersion.Original, Nothing)})
        '
        'SqlConnection1
        '
        Me.SqlConnection1.ConnectionString = "Data Source=MICROSOF-1EFBBC\THH;Initial Catalog=123;Persist Security Info=True;Us" & _
            "er ID=sa;Password=110119"
        Me.SqlConnection1.FireInfoMessageEventOnUserErrors = False
        '
        'SqlInsertCommand1
        '
        Me.SqlInsertCommand1.CommandText = "INSERT INTO yonghu(name, age, class, xuehao) VALUES (@name, @age, @class, @xuehao" & _
            "); SELECT name, age, class, xuehao FROM yonghu WHERE (xuehao = @xuehao)"
        Me.SqlInsertCommand1.Connection = Me.SqlConnection1
        Me.SqlInsertCommand1.Parameters.AddRange(New System.Data.SqlClient.SqlParameter() {New System.Data.SqlClient.SqlParameter("@name", System.Data.SqlDbType.VarChar, 10, "name"), New System.Data.SqlClient.SqlParameter("@age", System.Data.SqlDbType.VarChar, 10, "age"), New System.Data.SqlClient.SqlParameter("@class", System.Data.SqlDbType.VarChar, 10, "class"), New System.Data.SqlClient.SqlParameter("@xuehao", System.Data.SqlDbType.VarChar, 10, "xuehao")})
        '
        'SqlSelectCommand1
        '
        Me.SqlSelectCommand1.CommandText = "SELECT age, class, yonghu.*" & Global.Microsoft.VisualBasic.ChrW(13) & Global.Microsoft.VisualBasic.ChrW(10) & "FROM yonghu"
        Me.SqlSelectCommand1.Connection = Me.SqlConnection1
        '
        'SqlUpdateCommand1
        '
        Me.SqlUpdateCommand1.CommandText = resources.GetString("SqlUpdateCommand1.CommandText")
        Me.SqlUpdateCommand1.Connection = Me.SqlConnection1
        Me.SqlUpdateCommand1.Parameters.AddRange(New System.Data.SqlClient.SqlParameter() {New System.Data.SqlClient.SqlParameter("@name", System.Data.SqlDbType.VarChar, 10, "name"), New System.Data.SqlClient.SqlParameter("@age", System.Data.SqlDbType.VarChar, 10, "age"), New System.Data.SqlClient.SqlParameter("@class", System.Data.SqlDbType.VarChar, 10, "class"), New System.Data.SqlClient.SqlParameter("@xuehao", System.Data.SqlDbType.VarChar, 10, "xuehao"), New System.Data.SqlClient.SqlParameter("@Original_xuehao", System.Data.SqlDbType.VarChar, 10, System.Data.ParameterDirection.Input, False, CType(0, Byte), CType(0, Byte), "xuehao", System.Data.DataRowVersion.Original, Nothing), New System.Data.SqlClient.SqlParameter("@Original_age", System.Data.SqlDbType.VarChar, 10, System.Data.ParameterDirection.Input, False, CType(0, Byte), CType(0, Byte), "age", System.Data.DataRowVersion.Original, Nothing), New System.Data.SqlClient.SqlParameter("@Original_class", System.Data.SqlDbType.VarChar, 10, System.Data.ParameterDirection.Input, False, CType(0, Byte), CType(0, Byte), "class", System.Data.DataRowVersion.Original, Nothing), New System.Data.SqlClient.SqlParameter("@Original_name", System.Data.SqlDbType.VarChar, 10, System.Data.ParameterDirection.Input, False, CType(0, Byte), CType(0, Byte), "name", System.Data.DataRowVersion.Original, Nothing)})
        '
        'Button2
        '
        Me.Button2.Location = New System.Drawing.Point(248, 248)
        Me.Button2.Name = "Button2"
        Me.Button2.Size = New System.Drawing.Size(120, 56)
        Me.Button2.TabIndex = 9
        Me.Button2.Text = "删除"
        '
        'Form2
        '
        Me.AutoScaleBaseSize = New System.Drawing.Size(6, 14)
        Me.ClientSize = New System.Drawing.Size(448, 349)
        Me.Controls.Add(Me.Button2)
        Me.Controls.Add(Me.Button1)
        Me.Controls.Add(Me.TextBox4)
        Me.Controls.Add(Me.TextBox3)
        Me.Controls.Add(Me.TextBox2)
        Me.Controls.Add(Me.Label4)
        Me.Controls.Add(Me.Label3)
        Me.Controls.Add(Me.Label2)
        Me.Controls.Add(Me.TextBox1)
        Me.Controls.Add(Me.Label1)
        Me.Name = "Form2"
        Me.Text = "插入删除"
        Me.ResumeLayout(False)
        Me.PerformLayout()

    End Sub

#End Region

    Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
        '检查姓名。。。。。等是否为空
        If TextBox1.Text = "" Then
            MessageBox.Show("姓名不能为空")
        End If
        If TextBox1.Text = "" Then
            MessageBox.Show("年龄不能为空")
        End If
        If TextBox1.Text = "" Then
            MessageBox.Show("班级不能为空")
        End If
        If TextBox1.Text = "" Then
            MessageBox.Show("学号不能为空")
        End If
        '执行插入操作
        If MessageBox.Show("你确定要插入新的数据吗?", "数据插入", MessageBoxButtons.OKCancel, MessageBoxIcon.Information) = DialogResult.OK Then
            Try
                SqlConnection1.Open()
                Dim cmd As New SqlCommand
                cmd = SqlConnection1.CreateCommand
                cmd.CommandText = "insert into yonghu values('" + Trim(TextBox1.Text) + "','" + Trim(TextBox2.Text) + "','" + Trim(TextBox3.Text) + "','" + Trim(TextBox4.Text) + "')"
                cmd.ExecuteNonQuery()
                MessageBox.Show("数据插入成功")
                SqlConnection1.Close()
                TextBox1.Text = ""
                TextBox2.Text = ""
                TextBox3.Text = ""
                TextBox4.Text = ""

            Catch ex As Exception
                MessageBox.Show(ex.ToString)
            End Try
        Else

            TextBox1.Text = ""
            TextBox2.Text = ""
            TextBox3.Text = ""
            TextBox4.Text = ""

        End If
    End Sub

    Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button2.Click
        '查找你要删除的数据是否存在
        Try
            SqlConnection1.Open()
            Dim cmd As New SqlCommand
            cmd = SqlConnection1.CreateCommand
            cmd.CommandText = "select xuehao from yonghu where xuehao='" + Trim(TextBox4.Text) + "'"
            Dim dr As SqlDataReader
            dr = cmd.ExecuteReader
            If dr.Read <> -1 Then
                MessageBox.Show("你删除的数据不存在")
                dr.Close()
                SqlConnection1.Close()
                Exit Sub
            Else
                dr.Close()
                SqlConnection1.Close()
            End If
        Catch ex As Exception
            MessageBox.Show(ex.ToString)
        End Try
        '你删除的数据存在,执行删除操作
        If MessageBox.Show("你确定要删除此数据吗?", "删除数据", MessageBoxButtons.OKCancel, MessageBoxIcon.Information) = DialogResult.OK Then
            Try
                SqlConnection1.Open()
                Dim cmd As New SqlCommand
                cmd = SqlConnection1.CreateCommand
                cmd.CommandText = "delete from yonghu where xuehao='" + Trim(TextBox4.Text) + "'"
                cmd.ExecuteNonQuery()
                MessageBox.Show("数据删除成功")
                SqlConnection1.Close()
                TextBox1.Text = ""
                TextBox2.Text = ""
                TextBox3.Text = ""
                TextBox4.Text = ""

            Catch ex As Exception
                MessageBox.Show(ex.ToString)
            End Try
        Else
            TextBox4.Text = ""
        End If
    End Sub
End Class

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -