【问题标题】:Populating a CheckListBox in VB.NET在 VB.NET 中填充 CheckListBox
【发布时间】:2010-09-05 06:58:39
【问题描述】:

我有一个小要求,我请求任何人通过提供相同的源代码来帮助我。

要求如下:

您能否帮助我了解如何通过传递参数来调用存储过程,并根据存储过程返回的结果在 VB.NET 中填充 CheckListBox。

问候, 乔治

【问题讨论】:

  • @george-trevour ~ 我认为你有一些不好的信息,乔治。 A) Java != VB.NET ... B) 你的意思是 CheckBoxList 吗?检查 MSDN ... C)您已经尝试过什么? ... D) 这是用于 winforms 或 ASP.NET 应用程序吗?

标签: vb.net checkbox


【解决方案1】:
Imports System.Data
Imports System.Data.SqlClient

导入该命名空间并将以下代码写入某个方法并根据您的数据库和过程字段更改您的代码

'Set up Connection object and Connection String for a SQL Client
Using SQLCon As New SqlClient.SqlConnection
   SQLCon.ConnectionString = "Data Source=Server;User ID=User;Password=Password;"
   SQLCon.Open()

   Dim lDataTable As New DataTable
   Using SQLCmdAs New SqlCommand()
     SQLCmd.CommandText = "GetAuthors"  ' Stored Procedure to Call
     SQLCmd.CommandType = CommandType.StoredProcedure
     SQLCmd.Connection = SQLCon

     SQLCmd.Parameters.Add("AuthorName", SqlDbType.VarChar) 

     Dim daPubs As New SqlDataAdapter
     daPubs.SelectCommand = SQLCmd

     daPubs.Fill(lDataTable)
  End Using
End Using

CheckBoxList1.DataSource = lDataTable;
CheckBoxList1.DataTextField = "Name";
CheckBoxList1.DataValueField = "ID"
CheckBoxList1.DataBind();

Using Stored Procedures in Conjuction with DataAdapter

How to call SQL Server stored procedures in ASP.NET by using Visual Basic .NET

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2012-12-09
    • 2012-03-14
    • 1970-01-01
    相关资源
    最近更新 更多