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

datagrid databinding issue

Status
Not open for further replies.

phbrady

Programmer
Oct 17, 2003
41
US
Hi,

Simple error, can't find any other posts on it. I have a class which grabs data from a table using a stored proc, then populates a simple class and I'm using the class as the datasource for a datagrid in my user control. I've done the same thing with other classes with no trouble and I can't figure out what the difference is with this one. Here's the error code:

----------

A field or property with the name 'Count' was not found on the selected datasource.
at System.Web.UI.WebControls.BoundColumn.OnDataBindColumn(Object sender, EventArgs e) at System.Web.UI.Control.OnDataBinding(EventArgs e) at System.Web.UI.Control.DataBind() at System.Web.UI.Control.DataBind() at System.Web.UI.WebControls.DataGrid.CreateItem(Int32 itemIndex, Int32 dataSourceIndex, ListItemType itemType, Boolean dataBind, Object dataItem, DataGridColumn[] columns, TableRowCollection rows, PagedDataSource pagedDataSource) at System.Web.UI.WebControls.DataGrid.CreateControlHierarchy(Boolean useDataSource) at System.Web.UI.WebControls.BaseDataList.OnDataBinding(EventArgs e) at System.Web.UI.WebControls.BaseDataList.DataBind() at ProjectMgr.PickNote.DataBind() in c:\inetpub\ 28 at ProjectMgr.AddTask.Page_Load(Object sender, EventArgs e) in c:\inetpub\
-----------

"Count", of course, is not in my SELECT statement in the stored proc, or in the class that holds the data. This only happens if I have "Autogenerate Columns" turned on.

Thanks in advance,
Paul
 
User Control Code:

--------------------

Public Class PickNote
Inherits System.Web.UI.UserControl

#Region " Web Form Designer Generated Code "

'This call is required by the Web Form Designer.
<System.Diagnostics.DebuggerStepThrough()> Private Sub InitializeComponent()

End Sub
Protected WithEvents grdNotes As System.Web.UI.WebControls.DataGrid

'NOTE: The following placeholder declaration is required by the Web Form Designer.
'Do not delete or move it.
Private designerPlaceholderDeclaration As System.Object

Private Sub Page_Init(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Init
'CODEGEN: This method call is required by the Web Form Designer
'Do not modify it using the code editor.
InitializeComponent()
End Sub

#End Region

Public Overrides Sub DataBind()
Dim objNotes As New clsNotes

grdNotes.DataSource = objNotes.GetItems(Session("TASK_ID"))
grdNotes.DataBind()
End Sub

Public Sub New()

End Sub
End Class

Class Code:

------------------------

Public Class clsNote
Private _NoteID As Integer
Private _UserID As Integer
Private _TaskID As Integer
Private _DateTimeStamp As Date
Private _Note As String

Public Property NoteID() As Integer
Get
Return _NoteID
End Get
Set(ByVal Value As Integer)
_NoteID = Value
End Set
End Property
Public Property UserID() As Integer
Get
Return _UserID
End Get
Set(ByVal Value As Integer)
_UserID = Value
End Set
End Property
Public Property TaskID() As Integer
Get
Return _TaskID
End Get
Set(ByVal Value As Integer)
_TaskID = Value
End Set
End Property
Public Property TimeStamp() As Date
Get
Return _DateTimeStamp
End Get
Set(ByVal Value As Date)
_DateTimeStamp = Value
End Set
End Property
Public Property Note() As String
Get
Return _Note
End Get
Set(ByVal Value As String)
_Note = Value
End Set
End Property
Public Sub Save()
Dim objData As New clsData
objData.SaveNote(Me)
End Sub
End Class

------------------------

The Notes Class populates the Note Class:

------------------------

Public Class clsNotes
Inherits System.Collections.CollectionBase
Default Public Property Item(ByVal index As Integer) As clsNotes
Get
Return CType(list(index), clsNotes)
End Get
Set(ByVal Value As clsNotes)
list(index) = Value
End Set
End Property
Public Function Add(ByVal objNote As clsNote) As Integer
list.Add(objNote)
End Function
Public Sub Remove(ByVal index As Integer)
list.Remove(index)
End Sub
Public Function GetItem(ByVal intNoteID As Integer) As clsNote
Dim objNote As New clsNote
Dim objData As New clsData

Return objData.GetNoteByID(intNoteID)

End Function
Public Function GetItems(ByVal intTaskID As Integer) As clsNotes
Dim objData As New clsData

Return objData.GetNotesByTaskID(intTaskID)
End Function
End Class

------------------------

And here's the code from the clsData class:

------------------------

Public Function GetNotesByTaskID(ByVal intTaskID As Integer) As clsNotes
Dim objNotes As New clsNotes
Dim objResult As SqlDataReader
Dim objCommand As New SqlCommand(SP_NOTES_BY_TASK, objConnection)

Try
objCommand.CommandType = CommandType.StoredProcedure
objCommand.Parameters.Add("@TaskID", intTaskID)

objResult = objCommand.ExecuteReader

While objResult.Read
objNotes.Add(PopulateNote(objResult))
End While
objResult.Close()

Return objNotes

Catch ex As Exception
Err.Raise(ERR_NOTES_BY_TASK, , "Error Getting Notes (clsData.GetNotesByTaskID): " & ex.Message & " " & ex.StackTrace)
Finally
objCommand.Dispose()
End Try
End Function

------------------------

Public Function PopulateNote(ByVal recData As IDataRecord) As clsNote
Dim objNote As New clsNote

Try
objNote.NoteID = recData("pk_NoteID")
objNote.Note = recData("Notes")
objNote.TaskID = recData("fk_TaskID")
objNote.TimeStamp = recData("DateTimeStamp")
objNote.UserID = recData("fk_UserID")

Return objNote
Catch ex As Exception
Err.Raise(ERR_POPULATE_NOTE, , "Error Populating Note (clsData.PopulateNote): " & ex.Message & " " & ex.StackTrace)
End Try

End Function

--------------------

Here's the stored proc:

--------------------

CREATE PROCEDURE spGetNotesByTaskID
@TaskID int
AS
SELECT
*
FROM
Notes
WHERE
fk_TaskID = @TaskID


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

Part and Inventory Search

Sponsor

Back
Top