This code works though I don't understand why

  • Thread starter Thread starter Woody Splawn
  • Start date Start date
W

Woody Splawn

The code listed below works though I don't understand why. The code
is as follows:

Dim SelectCMD As SqlCommand = New SqlCommand("sp_CapEquipByDep",
PBConnection)
SelectCMD.CommandType = CommandType.StoredProcedure
Dim myParm As SqlParameter =
SelectCMD.Parameters.Add("@BudgetRoundID", SqlDbType.SmallInt)
myParm.Value = iBudgetRoundValue

Dim DaPB As SqlDataAdapter = New SqlDataAdapter
DaPB.SelectCommand = SelectCMD
iResult = DaPB.Fill(DS, "X")
rpt.DataSource = DS
rpt.DataMember = "X"

It would be helpful if someone could clarify. The part that I don't
understand has to do with the lines that read:

iResult = DaPB.Fill(DS ("X") and
rpt.DataMember = "X"

Tell me if I am right. I am creating a data adapter and telling it to use a
stored procedure as its source which I have identified in a SQLCommand
called SelectCMD. Additionally, I am telling the applicaiton to create a
table called X in a datase called DS and to fill it with data based on the
criteria in the stored procedure. Is this right?
 
Yes and at last you tell to use the table "X" from the dataset as a
datasource...

Patrice
 
Hi Woody,

Your understanding on the
iResult = DaPB.Fill(DS ("X") and
rpt.DataMember = "X"

is quite correct. The DataAdapter(DaPB)'s Fill method will fill the records
retrieved from the executed store procedure into a new created
DataTable(with the specified name "X") in the provided DataSet("DS")

Then, you set the DataSet("DS") to a databinding control ("rpt", is it a
repeater?) and specify its "DataMember" which is used to speicfy which
member(such as DataTable or a table's childRelation...) to be bind to the
control to display.

In addition, here are some other references on ADO.NET databinding:

#DbDataAdapter.Fill Method
http://msdn.microsoft.com/library/en-us/cpref/html/frlrfSystemDataCommonDbDa
taAdapterClassFillTopic.asp?frame=true

#Mapping Data-Source Columns to Dataset Data-Table Columns
http://msdn.microsoft.com/library/en-us/vbcon/html/vbtskmappingdatasourcecol
umnstodatasetdatatablecolumns.asp?frame=true

#Creating Master-Details Lists with the Windows Forms DataGrid Control
http://msdn.microsoft.com/library/en-us/vbcon/html/vbtskcreatingmasterdetail
slistwithdatagrid.asp?frame=true

Hope also helpful! Thanks.


Regards,

Steven Cheng
Microsoft Online Support

Get Secure! www.microsoft.com/security
(This posting is provided "AS IS", with no warranties, and confers no
rights.)

Get Preview at ASP.NET whidbey
http://msdn.microsoft.com/asp.net/whidbey/default.aspx
 
Back
Top