将多个数据项从SQL绑定到标签

时间:2013-03-26 18:12:05

标签: sql-server visual-studio-2010 visual-studio sql-server-2008 visual-studio-2008

如何将多个数据项从SQL绑定到标签?

这是我的代码:

    Dim str As String = ("Data Source=PC1; User ID=sa; Password=pwd;Databasfriend")
    Dim con As New SqlConnection(str)
    Dim str1 As String = "SELECT * FROM tbl_course"
    Dim da As New SqlDataAdapter(str1, con)
    Dim dataset1 As New DataSet()
    da.Fill(dataset1, "course")
    lbl.DataBindings.Add("text", dataset1, "course.Course_Code")

它仅绑定一个数据项,我想绑定特定列中的许多数据项

1 个答案:

答案 0 :(得分:0)

您可以在SQL语句中创建一个字符串并绑定到该字符串:

Dim str1 As String = "SELECT Course_Title + '(' + Course_Code + ')' AS lbl1 FROM tbl_course"

...

lbl.DataBindings.Add("text", dataset1, "course.lbl1")