Object reference not set to an instance of an object. for a DDL where source data sql
Object reference not set to an instance of an object. for a DDL where source data sql
Object reference not set to an instance of an object. for a DDL where source data sql
Object reference not set to an instance of an object. for a DDL where source data sql
Object reference not set to an instance of an object. for a DDL where source data sql
Object reference not set to an instance of an object. for a DDL where source data sql Object reference not set to an instance of an object. for a DDL where source data sql Object reference not set to an instance of an object. for a DDL where source data sql Object reference not set to an instance of an object. for a DDL where source data sql Object reference not set to an instance of an object. for a DDL where source data sql Object reference not set to an instance of an object. for a DDL where source data sql Object reference not set to an instance of an object. for a DDL where source data sql Object reference not set to an instance of an object. for a DDL where source data sql
Object reference not set to an instance of an object. for a DDL where source data sql Object reference not set to an instance of an object. for a DDL where source data sql
Object reference not set to an instance of an object. for a DDL where source data sql
Go Back  Xtreme Visual Basic Talk > > > Object reference not set to an instance of an object. for a DDL where source data sql


Reply
 
Thread Tools Display Modes
  #1  
Old 04-29-2013, 05:16 AM
whambham whambham is offline
Newcomer
 
Join Date: Sep 2012
Posts: 9
Default Object reference not set to an instance of an object. for a DDL where source data sql


Hi has anyone else come across a similar issue as described below

I have a web form with several DDL and text boxes some of them have post backs some dont

the DDLs have 3 or 4 Values like Yes , No or Often, Regularly, Never

a user is able to select the values and save his selection results on a sql server and a record number is generated on the save.

he is also able to retrieve his results via the same record number Via a subroutine called RecordSrchId all the text boxes get populated most of the DDLs get populated and results are selected but some of the DDLs dont get selected.

The DDLs for example will have Yes, No results as values in the list of items. The retrieved data from the sql is presented in a datatable and the value is cascaded down via the correct ID of the items for example "mydatatable.Tables(0).Rows(0)(2).ToString" where my datatable is the datatable and (2) is the item number i get a value from mydatatable as i have tested this with a Label control so its not returning null and the DDl have the correct list of values also in the correct case formats but for some reason it will give me an error below

Object reference not set to an instance of an object.




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.NullReferenceException: Object reference not set to an instance of an object.

Source Error:



Line 1148:
Line 1149: crane_requirement_Frequency_40T0.Items.FindByText(mydatatable.Tables(0 ).Rows(0)(32).ToString).Selected = True Line 1150: Line 1151:

Source File: C:\inetpub\wwwroot\aspx\factfind\Default.aspx.vb Line: 1149

Stack Trace:



[NullReferenceException: Object reference not set to an instance of an object.]
FactFindMenu.recordidsrch() in C:\inetpub\wwwroot\aspx\factfind\Default.aspx.vb:1149
FactFindMenu.Srch_Record_Click(Object sender, EventArgs e) in C:\inetpub\wwwroot\aspx\factfind\Default.aspx.vb:1090
System.Web.UI.WebControls.Button.OnClick(EventArgs e) +111
System.Web.UI.WebControls.Button.RaisePostBackEvent(String eventArgument) +110
System.Web.UI.WebControls.Button.System.Web.UI.IPostBackEventHandler.R aisePostBackEvent(String eventArgument) +10
System.Web.UI.Page.RaisePostBackEvent(IPostBackEventHandler sourceControl, String eventArgument) +13
System.Web.UI.Page.RaisePostBackEvent(NameValueCollection postData) +36
System.Web.UI.Page.ProcessRequestMain(Boolean includeStagesBeforeAsyncPoint, Boolean includeStagesAfterAsyncPoint) +1565

the subroutine to retrive the date is below




Code:
Private Sub recordidsrch()

Dim searchFactfnd As New SearchFactFnd ' custom class used to retrive data From sql server

Dim mydatatable As New Data.DataSet ' Dataset/table used

        mydatatable = searchFactfnd.FactFNDTableID(Rcrd_num_Txt.Text) '  populates the dataset with the function FactFNDTableID via a record Id gained from a textbox and function returns a dataset/table

       contact_name.Text = mydatatable.Tables(0).Rows(0)(1).ToString

        crane_hireCranesFrequency.Items.FindByText(mydatatable.Tables(0).Rows(0)(30).ToString)

        crane_spendPA.Text = mydatatable.Tables(0).Rows(0)(31).ToString

        crane_requirement_Frequency_40T.Items.FindByText(mydatatable.Tables(0).Rows(0)(32).ToString).Selected =True ' Line give error if i include .Selected =True 

        Label4.Text = mydatatable.Tables(0).Rows(0)(32) ' gives me a result that can be found in the DDL

end sub



The HTML code dor the DDL is
Code:
<asp:DropDownList ID="crane_requirement_Frequency_40T" runat="server" CssClass="largeinput" AutoPostBack="True">

<asp:ListItem>Crane Requirements Frequency</asp:ListItem>

<asp:ListItem>Regularly</asp:ListItem>

<asp:ListItem>Often</asp:ListItem>

<asp:ListItem>Seldom</asp:ListItem>

<asp:ListItem>Never</asp:ListItem>

</asp:DropDownList>

I have tried several variations of the below
Code:
Items.FindByText(mydatatable.Tables(0).Rows(0)(32).ToString).Selected =True 

Items.FindByvalue(mydatatable.Tables(0).Rows(0)(32).ToString).Selected =True 

ddl.selectedvalue

ddl.selecteditem

if not ispostback then

'populate

end if

ddl.clearcontents
tried rewriting the html ddl to below and try variations above did not work
Code:
<asp:DropDownList ID="crane_requirement_Frequency_40T" runat="server" CssClass="largeinputd">

<asp:ListItem Text="Crane Requirements Frequency"Value="" />

<asp:ListItem Text="Regularly" Value="Regularly" />

<asp:ListItem Text="Often" Value="Often" />

<asp:ListItem Text="Seldom" Value="Seldom" />

</asp:DropDownList>


seriously stuck now any help whould be appreciated i know the values fro the data set are correct and not null and the values exist in the DDL could post back be causing this

Last edited by Flyguy; 04-29-2013 at 06:02 AM. Reason: Added [code][/code] tags
Reply With Quote
  #2  
Old 04-29-2013, 07:58 AM
whambham whambham is offline
Newcomer
 
Join Date: Sep 2012
Posts: 9
Default

Issue fixed the db server had the datatype as nchar(10) the xtra white spaces created the error
chnaged to nvarchar instead
Reply With Quote
Reply


Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off

Forum Jump

Advertisement:





Free Publications
The ASP.NET 2.0 Anthology
101 Essential Tips, Tricks & Hacks - Free 156 Page Preview. Learn the most practical features and best approaches for ASP.NET.
subscribe
Programmers Heaven C# School Book -Free 338 Page eBook
The Programmers Heaven C# School book covers the .NET framework and the C# language.
subscribe
Build Your Own ASP.NET 3.5 Web Site Using C# & VB, 3rd Edition - Free 219 Page Preview!
This comprehensive step-by-step guide will help get your database-driven ASP.NET web site up and running in no time..
subscribe
Object reference not set to an instance of an object. for a DDL where source data sql
Object reference not set to an instance of an object. for a DDL where source data sql
Object reference not set to an instance of an object. for a DDL where source data sql Object reference not set to an instance of an object. for a DDL where source data sql
Object reference not set to an instance of an object. for a DDL where source data sql
Object reference not set to an instance of an object. for a DDL where source data sql
Object reference not set to an instance of an object. for a DDL where source data sql Object reference not set to an instance of an object. for a DDL where source data sql Object reference not set to an instance of an object. for a DDL where source data sql Object reference not set to an instance of an object. for a DDL where source data sql Object reference not set to an instance of an object. for a DDL where source data sql Object reference not set to an instance of an object. for a DDL where source data sql Object reference not set to an instance of an object. for a DDL where source data sql
Object reference not set to an instance of an object. for a DDL where source data sql
Object reference not set to an instance of an object. for a DDL where source data sql
 
Object reference not set to an instance of an object. for a DDL where source data sql
Object reference not set to an instance of an object. for a DDL where source data sql
 
-->