Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Westi on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Insert value into datatable

Status
Not open for further replies.

mchoudhury

Programmer
Nov 26, 2004
71
GB
Hi guys,
I created this new column in my datatable through stored procedure. Inside that column i want to insert value from the code - whats hapeening as i am executing the code when in debug mode the value are being shown (the one to be retrived for the new column).
But i'm having problem in inserting these values into the column on my datatable. How can i write a code that will insert the values into my datatable so when executed these values are shown on the web page:

Public Shared Function getSavings() As DataTable
'
Dim cmd As New SqlCommand()
cmd.CommandType = CommandType.StoredProcedure
cmd.CommandText = "get_Savings"
Dim dr As DataRow

'cmd.Parameters(2).Value = dr.Item(2)


Return getDataTable(cmd)

Stored Proceduer:
SELECT
TS.TelephoneSupplierName, TCP.TelephoneCallPlanName, '' as [AnnualPrice]
FROM tblTelephoneSuppliers TS
INNER JOIN tblTelephoneCallPlans TCP ON TS.TelephoneSupplierID = TCP.TelephoneSupplierID
INNER JOIN tblTelephoneServicePlans TSP ON TCP.TelephoneCallPlanID = TSP.TelephoneCallPlanID


FinalTotal2 = MCLocalTotal + MCNationalTotal + MCTotalCountries + MobileTotal

Public dtSavings As DataTable
dtSavings.Rows(i).Item("AnnualPrice") = (FinalTotal2 * 12)

in debug mode the value of item.array at 3 shows the value of annualprice, but i need to insert that value in the datatable so it can be shown in the web page through datagrid.

Datasource="<%# FRI.SOMB.Visitor.DataProvider.getSavings %>"
<asp:templatecolumn headertext="Annual Price" ItemStyle-BackColor="#66cc33" HeaderStyle-BackColor="#66cc33" HeaderStyle-Font-Bold="True">
<itemtemplate>
<%# DataBinder.Eval(Container.DataItem, "AnnualPrice") %>
</itemtemplate>
</asp:templatecolumn>

Thanks
Mac
 
your coding did not function therefore i amended the question a bit
 
Are you trying to add the FinalTotal value to each row? If so, you will need to loop through the datatable and assign the newly added column that value.

-Rick

----------------------
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top