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 strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

datarelation with stored procedure

Status
Not open for further replies.

florens

IS-IT--Management
Nov 13, 2002
50
NL
I've got a problem with making a datarelation in asp.net. I've done it on other pages, but on this page, it just won't work which kept me staring myself blind on some code for the last hours.

This is my code in vb.net:
Code:
'Set SQL Stored Procedure name...
        mSqlString = "exec klantGetKennis "                  '<---------- Stored Proc Name  
        mSqlString = mSqlString & klantIdParent.Text           '  ...and parameter = current parent record Id in hidden field...
        ds = New DataSet
        dv = New DataView


        'Get connection string from Web.Config
        mConnString = ConfigurationSettings.AppSettings("dbConnStr")
        
        cn = New SqlConnection
        cn.ConnectionString = mConnString
        
    'Open connection, get data set:
        cn.Open()
        adap = New SqlDataAdapter(mSqlString, cn)
        adap.Fill(ds, "dsMyDataKennis")

        'make tables in dataset
        ds.Tables(0).TableName = "kennisverzekering"
        ds.Tables(1).TableName = "medewerker"
        ds.Tables(2).TableName = "kennisverzekering_registratie"

        'define relation columns
        dc1 = ds.Tables("kennisverzekering").Columns("kennisverzekering_id")
        dc2 = ds.Tables("medewerker").Columns("kennisverzekering_registratie_kennisverzekering_id")
        dc3 = ds.Tables("kennisverzekering_registratie").Columns("kennisverzekering_registratie_kennisverzekering_id")

        'create the relations for the data: Relation Parent => Child - kennis => registratie
        dr1 = New DataRelation("kennisRegistratie", dc1, dc2, False)
        dr2 = New DataRelation("kennisUren", dc1, dc3, False)

        ds.Relations.Add(dr1)
        ds.Relations.Add(dr2)

        dv = ds.Tables("kennisverzekering").DefaultView

        If Not cn Is Nothing Then cn.Close()

        hgKennis.DataSource = dv
        hgKennis.DataBind()

My stored procedure:
Code:
CREATE PROCEDURE [florens].[klantGetKennis ] 

        @KlantIdIn   int     

AS


/* get kennisgegevens */
Select
    
    kennis.kennisverzekering_id        ,
    kennis.kennisverzekering_naam    ,
    kennis.kennisverzekering_begin_datum,
    kennis.kennisverzekering_eind_datum    ,
    kennis.kennisverzekering_contracturen,
    kennis.kennisverzekering_uurtarief    

From
    kennisverzekering as    kennis

Where
    kennis.kennisverzekering_klant_id        = @KlantIdIn


/* get registration and coworkers,*/
Select
    reg.kennisverzekering_registratie_id    ,
    reg.kennisverzekering_registratie_kennisverzekering_id,
    reg.kennisverzekering_registratie_datum    ,
    reg.kennisverzekering_registratie_uren    ,
    reg.kennisverzekering_registratie_omschrijving,
    reg.kennisverzekering_registratie_onsite    ,
    medewerker.medewerker_naam        

From
    kennisverzekering_registratie    as    reg

Inner join
    kennisverzekering on  reg.kennisverzekering_registratie_kennisverzekering_id = kennisverzekering.kennisverzekering_id

Inner join
    medewerker on  reg.kennisverzekering_registratie_medewerker_id = medewerker.medewerker_id


/* get hour total*/
Select
    sum(registratie.kennisverzekering_registratie_uren) as som_uren,
    registratie.kennisverzekering_registratie_kennisverzekering_id 

From
    kennisverzekering_registratie as registratie

Group by
    registratie.kennisverzekering_registratie_kennisverzekering_id
GO

The grid on the page is fairly straight-forward. It has all the fields, and as datakeyfield: kennisverzekering_id .

I want to get all the kennisverzekeringen (difficult to explain, but some sort of Service Level Agreement with customers), related to the customers on my page. I want to see all the registrations, our coworkers (medewerkers) have made to these kennisverzekeringen. And very important, I want to see the sum of these registrations for each kennisverzekering.

The error I get is:
Code:
field or property with the name 'som_uren' was not found on the selected datasource. 
Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code. 

Exception Details: System.Web.HttpException: A field or property with the name 'som_uren' was not found on the selected datasource.

Source Error: 


Line 139:
Line 140:        hgKennis.DataSource = dv
Line 141:        hgKennis.DataBind()
Line 142:        MyGridDataGetKennis = True
Line 143:    End Function
 

Source File: bla\grids\kennisverzekering.ascx.vb    Line: 141 

Stack Trace: 


[HttpException (0x80004005): A field or property with the name 'som_uren' was not found on the selected datasource.]
   System.Web.UI.WebControls.BoundColumn.OnDataBindColumn(Object sender, EventArgs e) +349
   System.Web.UI.Control.OnDataBinding(EventArgs e) +66
   System.Web.UI.Control.DataBind() +26
   System.Web.UI.Control.DataBind() +86
   System.Web.UI.WebControls.DataGrid.CreateItem(Int32 itemIndex, Int32 dataSourceIndex, ListItemType itemType, Boolean dataBind, Object dataItem, DataGridColumn[] columns, TableRowCollection rows, PagedDataSource pagedDataSource) +169
   System.Web.UI.WebControls.DataGrid.CreateControlHierarchy(Boolean useDataSource) +1408
   System.Web.UI.WebControls.BaseDataList.OnDataBinding(EventArgs e) +49
   System.Web.UI.WebControls.BaseDataList.DataBind() +23
   backoffice.kennisverzekering.MyGridDataGetKennis() in bla\grids\kennisverzekering.ascx.vb:141
   backoffice.kennisverzekering.Page_Load(Object sender, EventArgs e) in bla\grids\kennisverzekering.ascx.vb:32
   System.Web.UI.Control.OnLoad(EventArgs e) +67
   System.Web.UI.Control.LoadRecursive() +35
   System.Web.UI.Control.AddedControl(Control control, Int32 index) +307
   System.Web.UI.ControlCollection.Add(Control child) +153
   backoffice.navbar.setPlaceHolder(String keuze) in bla\gui\navbar.ascx.vb:145
   backoffice.navbar.onButtonClick(Object sender, EventArgs e) in bla\gui\navbar.ascx.vb:212
   System.Web.UI.WebControls.Button.OnClick(EventArgs e) +108
   System.Web.UI.WebControls.Button.System.Web.UI.IPostBackEventHandler.RaisePostBackEvent(String eventArgument) +57
   System.Web.UI.Page.RaisePostBackEvent(IPostBackEventHandler sourceControl, String eventArgument) +18
   System.Web.UI.Page.RaisePostBackEvent(NameValueCollection postData) +33
   System.Web.UI.Page.ProcessRequestMain() +1277

A lot of code, but I hope someone sees what I'm doing wrong.

Oh, btw, I've tried to change the sum field to some other field, but this didn't work either.
Thanks!
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top