views:

37

answers:

1

Dear All,

I have a small requirement and i request anyone to help me out by providing the source code for the same.

The requirement is as follows:

Can you please help me as to how to call a stored procedure by passing paramenters and populate a CheckListBox in VB.NET based on the results returned from the stored procedure.

Regards, George

A: 
Imports System.Data
Imports System.Data.SqlClient

import that namespace and write the following code to some method and change your code According to your Database and Procedure Fields

'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

Azhar
Dear Azhar, thanks a lot for your help. Have a great day.
George Trevour Dsouza