data view's filter vs. data adapter's SELECT command

doing


objectDataSet.Tables["TableA"].DefaultView.RowFilter = "TableA_ID=" +
dropDownListControl.SelectedItem.Value.ToString();

or

objectDataAdapter.SelectCommand.CommandText = "SELECT * FROM TableA " +
" WHERE TableA_ID =" + dropDownListControl.SelectedItem.Value.ToString();

i thought both statements should represent the same thing, but the second one gave me a
System.NullReferenceException: Object reference not set to an instance of an object
error - would be possible just with those pieces of code to figure out them?
thanks for any assistance
0
lofquest
3/1/2004 1:06:47 PM
asp.net.getting-started 91979 articles. 4 followers. Follow

5 Replies
877 Views

Similar Articles

[PageSpeed] 59

I guess dropdown list doesn't have any item selected, thats why.
0
AnatolyR
3/1/2004 2:24:44 PM
I wouldn't be surprised if your dropdown maybe doesn't have a selecteditem yet. You might try stepping through this in the debugger to find out what doesn't exist yet.
Jim


MS MVP ASP.NET [VC++/MFC emeritus]


Old Dog Learns New Tricks

Preferred programming language: cuneiform on clay tablets
0
JimRoss
3/1/2004 2:27:46 PM
thanks Jim for assistance

drop down list is already populated from an access db and shows first item fine - i get that error when selecting any item
i ensure you that each item is retrieving a value
i can not understand what kind of debugger you're talking about - i tried 'run to cursor' into VS but still can not locate trouble
0
lofquest
3/1/2004 2:56:26 PM
Yes, I was talking about the VS debugger. Set a breakpoint on the line where you're getting the error, then inspect the items on that line. I'll bet you'll find that the dropdown's "SelectedIndex" is -1. 

One thing that might be "getting" you, if you're getting this error after a "SelectedIndexChanged" postback, is re-binding the dropdown in PageLoad without checking "not IsPostBack", so you end up re-binding it (and thus clearing the selection) before you get to the code that's trying to use the selected item.
Jim


MS MVP ASP.NET [VC++/MFC emeritus]


Old Dog Learns New Tricks

Preferred programming language: cuneiform on clay tablets
0
JimRoss
3/1/2004 3:17:05 PM
SelectedIndex Value matches to each one selected no error, however cachedSelectedIndex returns -1, what does it mean please?

i'm using caching and not re-binding outside postback:

private void Page_Load(object sender, System.EventArgs e)
{
if ((!IsPostBack) || (Cache.Get("objDataSet") == null))
{
// data adapter
objDataAdapter = new OleDbDataAdapter("SELECT * FROM Contacts", objConnection);
// fill data table
objDataAdapter.Fill(objDataTable);
// data adapter (table 2)
objDataAdapter.SelectCommand.CommandText = "SELECT * FROM Calls";
// data table 2
DataTable objDataTable2 = new DataTable("Calls");
// fill data table 2
objDataAdapter.Fill(objDataTable2);
// add tables to data set
objDataSet.Tables.Add(objDataTable);
objDataSet.Tables.Add(objDataTable2);
// Cache data set for 20 minutes.
Cache.Add("objDataSet", objDataSet, null, DateTime.MaxValue,
System.TimeSpan.FromMinutes(20),
System.Web.Caching.CacheItemPriority.Default, null);
// bind dropdown
drpContacts.DataBind();
}
else
// If this is post-back get the Cached data set.
objDataSet = (DataSet) Cache["objDataSet"];
}
0
lofquest
3/1/2004 4:02:23 PM
Reply:

Similar Artilces:

The value's length for key 'data source' exceeds it's limit of '128'.
Hii, When I tried to bind dropdownlist to database by declaring connection string in the code behind file I am getting this error: The value's length for key 'data source' exceeds it's limit of '128'. 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.ArgumentException: The value's length for key 'data source' exceeds it's limit of '128'.Source Error: An...

is it possible write cloumn's data and checkbox's data in the same time?
  I'm editing a asp.net web by using vs 2005 c#, I've a webForm including a gridview and a checkboxlist, the checkbotlist is for authentication selecting of grideview's data. I'm wondering is it possible write gridview and checkboxlist' data in tha same time? if it's possible howcome?     sorry for my poor english.. the expression maybe is not very good to understanding.. hope anyone here could to me a favor to resolve this question.   thank you very much  and have a nice day ! Hi,    It is impossible to write GridView and CheckBoxList at the th...

what's the best way to save data if it's 2 webforms/pages data?
I am working on the web application for recruiting, I split the application for employment into 2 web forms.  After user compeleted the first web form, he has to click "continue" to go to 2nd page and fill out the application, then click "Submit" to save data and send out application by fax. The question is : what is the appropriate way to save data?  when user click "continue" on first page, should I save it on this stage or what should I do?  because I am thinking that if user didn't submit the form but just exit the page, then how can I roll back all the data that I just s...

DropDownList won't insert data into table that's getting the data from
 The title pretty much says it all. All other rows get populated in the table during insert but Owner_id & Title_id which are foreign keys (owner_id is a FK in the same table (is it possible to do something like that?).Don't know where the problem is so hope you have the answers (and please, post simple answers (not sure i can comprehend the complicated ones).Here's the code: 1 <%@ Page Language="VB" MasterPageFile="~/MasterPage.master" Title="nevermind" %> 2 3 <script runat="server"> 4 5 Protected...

Database Data Type Design (Strings vs. 1's and 0's)
 Hello guys, I am a hobbyist programmer and now that I have started asp.net, I was wondering about the correct way to enter data into a table.  For example, i have a table called players with a field called status.  What should I code the status as?  "Active" or "Retired" or 1 and 0? I thought using 1 and 0 would be better as far as database size, but it is pretty difficult to understand how to modify the gridview.  I come from PHP and everything is a lot more accesible there as far as modification of output.  Thanks in advance! I a...

Urgent Help! How to get data from child's gridview to parent's textbox
 Hello Sir,Would you please advise me, how can I get the data from child gridview to parent textbox.For example, I have select 2 row in child's datagrid the values are "A" and "B" then click add and "A B" appears in the same parent's textbox. Thanks in advance!   Anyone please help me. How to get the data from gridview on popup page to textbox on the main page. Thank you so much!!!! Hi Novox , Please check my sample :   <asp:GridView ID="GridView1" runat="server" Height="227px" Width...

Opera's widgets vs IE's ActiveX vs FF's extentions.
I've asked the difference on Opera's forum http://my.opera.com/community/forums/topic.dml?id=3D152376 The widgets designer answers some my paranoid quiestions. Tony. In grc.security Anthony OZ wrote: > I've asked the difference on Opera's forum > http://my.opera.com/community/forums/topic.dml?id=152376 > > The widgets designer answers some my paranoid quiestions. Ahh... Thanks for posting. While it all sounds reassuring, I am not yet "supremely confident" here. I knew OS would follow it's security minded approach, but as with ...

Urgent Help! How to get data from child's gridview to parent's textbox #2
 Hello Sir,Would you please advise me, how can I get the data from child gridview to parent textbox?For example, I have select 2 row in child's datagrid the values are "A" and "B" then click add and "A B" appears in the parent's textbox. I think this must use JavaScript to make this happen but I have no idea, please help! Thanks in advance!  parent page : <html xmlns="http://www.w3.org/1999/xhtml" ><head runat="server"> <title>Untitled Page</title></head><body> <form...

When viewing a ng I'm having problems with choosing what to view. It's like this. When scrolling through the posts my reader wants to view every thread. Let's say I read a particular post. It's highli
When viewing a ng I'm having problems with choosing what to view. It's like this. When scrolling through the posts my reader wants to view every thread. Let's say I read a particular post. It's highlighted because I chose to read it. Then after I am done and scroll down, instead of the highlight moving, it stays centered and wants to read/open every post that I'm scrolling through even though I haven't clicked on it and I don't want to read it. This also affects choosing which ng to read. Things want to scroll when I am not wanting them too. When I ...

How to send http request including POST's or GET's Data and triggering the event of web pgae!
http://svr1/Login.aspx <Html>...<Body><form id="Form1" method="post" runat="server"><asp:TextBox id="txtUserName" runat="server"></asp:TextBox><asp:TextBox id="txtPwd" runat="server"></asp:TextBox><asp:Button id="btnLogin" runat="server" Text="Login"></asp:Button><asp:Label id="Label1" runat="server"> </asp:Label></form></Body></Html> Codebehind Login.aspx.cs…private void btnLogin_Click(object sender, System.EventArgs e){if((txtUserName.Text=="Peter")&&(txtPwd.Text=="1234")){Label1.Text="succe...

Where There's Data Stored, There's A Risk
"BUSINESSES THROUGHOUT THE REGION THAT handle large amounts of personal information have found one sure-fire way of avoiding security breaches: collect less data."... <http://www.theday.com/re.aspx?re=f34df362-157f-43fd-a990-77ba17fa54b9> or http://preview.tinyurl.com/253a5y -- js http://justheadlines.awardspace.com ...

Insert's with apostrophe's in data.
Is there any way of inserting strings with apostrophe's in them into character fields without doubling up the apostrophe's? For example: insert into mytable ( charfield1 ) values ('don't blow up on me') blows up because of the apostrophe being treated as the string terminator. It works when I do: insert into mytable ( charfield1 ) values ('don''t blow up on me') (that is two single-quotes, not one double-quote). Is there any other alternative, such as an alternate string delimiter? I can't SET quoted_identifier OFF because some of...

Why can't I Enable Editing on a Gridview that gets it's data from a View through an SqlDataSource?
Hi, I think the title explains it all really. I cannot configure the SqlDataSource to add Insert, Update and Delete statements - not through the wizard anyway. The view combines two tables, each containing 3 columns. I have tried using different combinations of columns, and ended up selecting all of them (making sure the foreign key column of the first table was given a different alias to the primary key column of the second table) but I still cannot enable editing. Cheers, PatrickDisco Patrick writes web applications using:Visual Studio 2008ASP.NET 3.5C#SQL Server 2008 Use stored pr...

How can I get out of my Mozilla's browser the Winamp browser and get back the Google's or Mozilla's browser.
Please I have got to my browser ( I don't know how.) the Winamp browser he behave like virus stick in.But he doesn't has uninstalation section so I can't do anything to get him away from Mozilla's file. I'm not happy of Winamp's behave its like advertisement against a customer's will. Please is there any way to get him away from Mozilla?Please send me exact direction I have tried many ways but he is deeply inside the systeme so when I install new Mozilla he is always here ready to pester me. Thank you for an answer. Richard ...

Web resources about - data view's filter vs. data adapter's SELECT command - asp.net.getting-started

Resources last updated: 2/3/2016 9:30:38 AM