datalist troubles

Results 1 to 3 of 3

Thread: datalist troubles

  1. #1
    Join Date
    Dec 1969

    Default datalist troubles

    All, <BR><BR>Im having some serious datalist troubles. I keep getting this error: "Object reference not set to an instance of an object.<BR>". I dont know where this occuring since its compiling without any errors. Im about ready to pull an Elvis on my computer ;-(<BR>is there a way to output what the offending line number is causing this?<BR><BR>System: XP Pro<BR>.NET sp 2<BR><BR><BR>below is the code<BR>****************************************** ********<BR><BR>ASPX:<BR>_________________________ ___________________________________<BR>&#060;ecomm erce:StringList id="objStringGrid" Width="500" <BR>GridWidth="100%" ShowGridLines="Y" <BR>CellSpacing="0" CellPadding="0" <BR>BodyClass="" <BR>TextClass="Text" <BR>BoldTextClass="TextBold" runat="server" /&#062;<BR><BR>ASCX:<BR>___________________________ ___________________________________<BR>&#060;%@ Control inherits="StringListClass" ClassName="StringList" %&#062;<BR>&#060;asp:DataList ID="objStringGrid" runat="server"&#062;<BR> &#060;ItemTemplate&#062;<BR> &#060;table border="0" width="100%" cellspacing="0" cellpadding="5"&#062;<BR> &#060;tr&#062;<BR> &#060;td align="left" valign="top"&#062;<BR> &#060;font class="&#060;%=TextClass%&#062;"&#062;<BR> &#060;%# DataBinder.Eval(Container.DataItem, "name") %&#062;<BR> &nbsp;<BR><BR> &#060;/font&#062;<BR> &#060;/td&#062;<BR> &#060;/tr&#062;<BR> &#060;/table&#062; <BR> &#060;/ItemTemplate&#062;<BR>&#060;/asp:DataList&#062;<BR><BR><BR>StringListClass.vb:< BR>_______________________________________________ ____________<BR>Imports System<BR>Imports System.Web.UI<BR>Imports System.Web.UI.WebControls<BR><BR>Imports System.Web.UI.Control<BR>Imports System.Data<BR>Imports System.Data.DataTable<BR>Imports System.Configuration<BR>Imports System.Drawing<BR>Imports System.Data.OleDB<BR>Imports System.Data.SqlClient<BR>Imports System.Xml<BR><BR><BR>Public Class StringListClass<BR> Inherits UserControl<BR><BR> Private iGridWidth As Unit = Unit.Percentage(100)<BR> Private iGridBorder As Unit = Unit.Pixel(1)<BR> Private sShowGridLines As String = "y"<BR> Private uWidth As Unit = Unit.Pixel(350)<BR> Private iCellSpacing As Integer = 0<BR> Private iCellPadding As Integer = 0<BR> Private sBodyClass As String = ""<BR> Private sTextClass As String = "PageText"<BR> Private sBoldTextClass As String = "PageTextBold"<BR> Private colBorderColor As Color = System.Drawing.Color.Gray<BR> Private sGridClass As String = "GridBorder"<BR><BR> Public lblError As Label<BR> Public lblResults As Label<BR> Public objStringGrid As DataList<BR> Public tblMain As Table<BR><BR> Sub Page_Load(ByVal Sender As Object, ByVal E As EventArgs)<BR><BR> If Not Page.IsPostBack() Then<BR><BR> &#039; Populate Controls<BR> tblMain.Width = uWidth<BR> tblMain.CssClass = sBodyClass<BR> objStringGrid.CellPadding = iCellPadding<BR> objStringGrid.CellSpacing = iCellSpacing<BR> objStringGrid.CssClass = sGridClass<BR> <BR> lblResults.CssClass = BoldTextClass<BR><BR> Dim ThisUser As New StoreObjects.User(Context.User.Identity.Name)<BR>< BR> Dim objString As DataTable<BR><BR> Try<BR> <BR> objString = ThisUser.StringJobs.ToDataTableTest()<BR> Catch Ex As Exception<BR> lblError.Text = Ex.Message<BR> End Try<BR><BR><BR> &#039; Clean Up <BR> ThisUser = Nothing<BR><BR> &#039; Populate Grid<BR> If sShowGridLines.ToUpper() = "Y" Then<BR> objStringGrid.GridLines = GridLines.Both<BR> Else<BR> objStringGrid.GridLines = GridLines.None<BR> End If<BR> objStringGrid.Width = iGridWidth<BR> objStringGrid.BorderWidth = iGridBorder<BR> objStringGrid.DataSource = objStringJobs<BR> objStringGrid.RepeatDirection = RepeatDirection.Vertical<BR> objStringGrid.DataBind()<BR><BR> End If<BR> End Sub<BR>End Class<BR><BR><BR>Core.vb<BR>______________________ _____________________________________<BR>Public Function ToDataTable() As DataTable<BR> Dim sSQLCommand As String = ""<BR> sSQLCommand = "SELECT "<BR> sSQLCommand += "id,userID,FirstName,<BR> sSQLCommand += " FROM string WHERE"<BR> sSQLCommand += " userID=&#039;" & sUserID & "&#039;"<BR><BR> Dim objResults As New DataTable("Products")<BR> objResults.Columns.Add("id", System.Type.GetType("System.String"))<BR> objResults.Columns.Add("userID", System.Type.GetType("System.String"))<BR> objResults.Columns.Add("FirstName", System.Type.GetType("System.String"))<BR> <BR><BR> Dim Conn As New OleDbConnection(_DSN)<BR> Dim Command As New OleDbCommand(sSQLCommand, Conn)<BR> Dim drReader As OleDbDataReader<BR> Try<BR> Conn.Open()<BR> drReader = Command.ExecuteReader()<BR> Dim objRow As DataRow<BR><BR> While drReader.Read()<BR> objRow = objResults.NewRow()<BR> objRow("id") = drReader("id")<BR> objRow("userID") = drReader("userID")<BR> objRow("FirstName") = drReader("FirstName")<BR> objResults.Rows.Add(objRow)<BR> End While<BR><BR> Catch Ex As Exception<BR> Throw New ArgumentException("Error:" & "[" & Ex.Message & "][" & Ex.Source & "]")<BR> Finally<BR> Conn.Close()<BR> End Try<BR> Return objResults<BR> End Function

  2. #2
    Join Date
    Dec 1969

    Default What line generates the error?

    You may want to try:<BR>Protected WithEvents lblError As Label <BR>Protected WithEvents lblResults As Label <BR>Protected WithEvents objStringGrid As DataList <BR>Protected WithEvents tblMain As Table <BR><BR>&#039; instead of "Public"<BR><BR>And *** is <BR>objStringJobs? It just appears in your code out of left field.

  3. #3
    Join Date
    Dec 1969

    Default RE: datalist troubles

    Well..<BR> I think i have fasced a lot these probelms.. Check if u have given "NEW" while declarinf the variables... This error message corresponds only to that trouble..<BR><BR>Happy Coding!<BR>Sri!

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts