VB.net2008中怎么让SQl语句查询的结果显示在MSGBOX中

lzf3211 发布于 2012/08/24 17:11
阅读 1K+
收藏 0

云原生2.0展望丨从“小众”到“首选”,推动云原生产业落地华为云作用几何?>>>

Imports System.Data

Imports System.Data.SqlClient

 

Public Class Form1

    Dim str As String = ""

    Dim hm As String = ""

 

    Private Sub TextBox2_KeyUp(ByVal sender As Object, ByVal e As System.Windows.Forms.KeyEventArgs) Handles TextBox2.KeyUp

 

        If (e.KeyValue > 47 And e.KeyValue < 58) Or (e.KeyValue > 95 And e.KeyValue < 106) Or (e.KeyValue = 8) Or (e.KeyValue = 45) Or (e.KeyValue = 46) Then

            str = TextBox2.Text

            Label9.Text = ""

        Else

            Label9.Text = "请输入正整数"

            TextBox2.Text = str

            TextBox2.Focus()

        End If

    End Sub

 

    Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click

        Dim conn As SqlConnection = New SqlConnection()

        '定义数据库

        conn.ConnectionString = "Data Source=XPTEXT;Initial Catalog=QQ2012;Integrated Security=True"

        Dim selectcmd As SqlCommand = New SqlCommand()

        selectcmd.CommandText = "select 呢称,密码,年龄,性别,真实姓名,星座,血型 from Users"

        selectcmd.Connection = conn

        Dim insertcmd As SqlCommand = New SqlCommand()

        insertcmd.CommandText = "insert into Users values(@呢称,@密码 ,@年龄,@性别,@真实姓名 ,@星座,@血型)"

        insertcmd.Connection = conn

        Dim spuname As SqlParameter = New SqlParameter("@呢称", SqlDbType.VarChar, 10)

        spuname.SourceColumn = "呢称"

        insertcmd.Parameters.Add(spuname)

        insertcmd.Parameters.Add("@密码", SqlDbType.VarChar, 16, "密码")

        insertcmd.Parameters.Add("@年龄", SqlDbType.VarChar, 32, "年龄")

        insertcmd.Parameters.Add("@性别", SqlDbType.VarChar, 16, "性别")

        insertcmd.Parameters.Add("@真实姓名", SqlDbType.VarChar, 16, "真实姓名")

        insertcmd.Parameters.Add("@星座", SqlDbType.VarChar, 16, "星座")

        insertcmd.Parameters.Add("@血型", SqlDbType.VarChar, 16, "血型")

        Dim da As SqlDataAdapter = New SqlDataAdapter()

        da.InsertCommand = insertcmd

        da.SelectCommand = selectcmd

        Dim ds As DataSet = New DataSet()

        da.Fill(ds, "Users")

        Dim drnew As DataRow = ds.Tables("Users").NewRow()

        If TextBox1.Text = "" Then

            MsgBox("请您输入呢称后注册!", MsgBoxStyle.OkOnly, "友情提示")

            TextBox1.Focus()

            Exit Sub

        Else

            drnew("呢称") = TextBox1.Text

        End If

 

        If TextBox2.Text = "" Then

            MsgBox("请输入您的年龄后注册!", MsgBoxStyle.OkOnly, "友情提示")

            TextBox2.Focus()

            Exit Sub

        ElseIf TextBox2.Text = str Then

            drnew("年龄") = TextBox2.Text

        End If

 

        If RadioButton1.Checked = True Then

            drnew("性别") = RadioButton1.Text

        ElseIf RadioButton2.Checked = True Then

            drnew("性别") = RadioButton2.Text

        Else

            MsgBox("请选择性别后再注册!", MsgBoxStyle.OkOnly, "友情提示")

            Exit Sub

        End If

 

        If TextBox3.Text <> TextBox4.Text Then

            MsgBox("再次密码输入不一样,注册不成功!", MsgBoxStyle.OkOnly, "注意")

            TextBox3.Text = ""

            TextBox4.Text = ""

            Exit Sub

        ElseIf TextBox3.Text = "" Then

            MsgBox("请您输入密码后再注册!", MsgBoxStyle.OkOnly, "友情提示")

            Exit Sub

        Else

            drnew("密码") = TextBox3.Text

        End If

 

        drnew("真实姓名") = TextBox5.Text

        drnew("星座") = ComboBox1.Text

        drnew("血型") = ComboBox2.Text

        ds.Tables("Users").Rows.Add(drnew)

        da.Update(ds, "Users")

 

    End Sub

 

    Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button2.Click

        Me.Close()

        Form2.Show()

    End Sub

End Class

代码如上,要把select 号码 from Uesrs where 号码 in(select max(号码) from Uesrs) 的结果显示该怎么写。各位大虾帮帮忙 

加载中
返回顶部
顶部