将具有多个表的存储过程的数据显示到文本框中 [英] Displaying data from stored procedures with multiple tables into textbox

查看:161
本文介绍了将具有多个表的存储过程的数据显示到文本框中的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

SELECT 
    Login.LoginID, Student.[Student Name], Student.[Student address], Student.StudentID
FROM
    Login 
INNER JOIN
    Student ON Login.LoginID = Student.LoginID
WHERE
    (Login.username = @user) AND (Login.password = @pass)

RETURN 

如何在多个文本框中显示学生姓名,学生地址,StudentID和LoginID?

How do I display the Student Name, Student Address, StudentID, and LoginID into multiple textboxes?

推荐答案

以下是如何从存储过程检索结果并将返回的列分配给文本框的示例:

Here's and example of how to retrieve results from our stored procedure and assign returned columns to text boxes:

Function GetInfoForStudent(ByRef QueryName As String, ByVal UserName As String, ByVal Password As String) As DataTable
    Using Con As New SqlConnection
        Try
            Using OleCon As New SqlConnection
                Dim Connection As String = "MyConnectionString"
                Con.Open()
                Dim Cmd As SqlCommand = Con.CreateCommand()
                Cmd.CommandType = CommandType.StoredProcedure
                Cmd.CommandText = QueryName
                Cmd.Parameters.AddWithValue("user", UserName)
                Cmd.Parameters.AddWithValue("password", Password)
                Dim da As New SqlDataAdapter(Cmd)
                Dim ds As New DataTable()
                da.Fill(ds)
                Return ds
            End Using
        Catch ex As Exception
            Throw New Exception(ex.Message)
        End Try
    End Using

End Function

Sub ShowStudentInfo()
    Dim dt As DataTable = GetInfoForStudent("MyStoredProcName", "MyUserName", "MyPasswword")
    ' Since (presumably) only one is returned
    With dt.Rows(0)
        ' Assign your text boxes 
        'LoginIDTextBox.Text = .Item("LoginID")
        'StudentNameTextBox.Text = .Item("Student Name")
        'StudentAddressTextBox.Text = .Item("Student address")
        'StudentIDTextBox.Text = .Item("StudentID")
    End With
End Sub

这篇关于将具有多个表的存储过程的数据显示到文本框中的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆