指定演员表不可用

时间:2014-04-13 14:05:24

标签: sql sql-server vb.net

有人可以帮我这个代码吗

表示指定演员阵容不可用

MysqlConn = New SqlConnection
    MysqlConn.ConnectionString =
        "Data Source=SABAHALI-SHEIKH;Initial Catalog=md_1103763;Integrated Security=True"
    Dim READER As SqlDataReader

    Try
        MysqlConn.Open()
        Dim Query As String
        Query = "SELECT [firstname] FROM md_1103763.dbo.customer where firstname='" & ComboBox1.Text & "'"
        COMMAND = New SqlCommand(Query, MysqlConn)
        READER = COMMAND.ExecuteReader
        While READER.Read
            TextBox1.Text = READER.GetInt32("customerID")
            TextBox2.Text = READER.GetString("firstname")
            TextBox3.Text = READER.GetString("surname")
            TextBox4.Text = READER.GetString("contactnumber")
            TextBox5.Text = READER.GetString("emailaddress")

        End While

        MysqlConn.Close()

    Catch ex As Exception
        MessageBox.Show(ex.Message)
    Finally
        MysqlConn.Dispose()


    End Try

2 个答案:

答案 0 :(得分:2)

MysqlConn = New SqlConnection
MysqlConn.ConnectionString =
    "Data Source=SABAHALI-SHEIKH;Initial Catalog=md_1103763;Integrated Security=True"
Dim READER As SqlDataReader

Try
    MysqlConn.Open()
    Dim Query As String
    Query = "SELECT [customerID], [firstname], [surname], [contactnumber], [emailaddress] FROM md_1103763.dbo.customer where firstname='" & ComboBox1.Text & "'"
    COMMAND = New SqlCommand(Query, MysqlConn)
    READER = COMMAND.ExecuteReader
    While READER.Read
        TextBox1.Text = READER.GetInt32(READER.GetOrdinal("customerID"))
        TextBox2.Text = READER.GetString(READER.GetOrdinal("firstname"))
        TextBox3.Text = READER.GetString(READER.GetOrdinal("surname"))
        TextBox4.Text = READER.GetString(READER.GetOrdinal("contactnumber"))
        TextBox5.Text = READER.GetString(READER.GetOrdinal("emailaddress"))

    End While

    MysqlConn.Close()

Catch ex As Exception
    MessageBox.Show(ex.Message)
Finally
    MysqlConn.Dispose()


End Try

答案 1 :(得分:0)

您必须选择表格中的所有列

Try
    MysqlConn.Open()
    Dim Query As String = Nothing
    Query = "SELECT * FROM md_1103763.dbo.customer where firstname='" + ComboBox1.Text & "'"
    COMMAND() = New SqlCommand(Query, MysqlConn)
    READER = COMMAND().ExecuteReader
    While READER.Read
        TextBox1.Text = READER("customerID").ToString()
        TextBox2.Text = READER("firstname").ToString()
        TextBox3.Text = READER("surname").ToString()
        TextBox4.Text = READER("contactnumber").ToString()
        TextBox5.Text = READER("emailaddress").ToString()
    End While


    MysqlConn.Close()
Catch ex As Exception
    MessageBox.Show(ex.Message)
Finally


    MysqlConn.Dispose()
End Try