I keep getting the error ExecuteReader: CommandText property has not been initialized and i'm not sure why it points to this line in my code
dd1.DataSource = LogData.StermQ2(datelistquery).Tables(0).DefaultView
dd1.DataBind()
dd1.Items.Insert(0, new listitem("Any location", "%"))
The top line is the one with the error
Any help would be much appreciated
Thanks
Jamie
I suspect it has something to do with your data source:
LogData.StermQ2(datelistquery)
Typically, when I'm working with some a SQLDataSource, I have to initialize is like so:
mydatasource.SelectCommand = "select * from mytable"
dd1.DataBind()
SelectCommand is the CommandText is the query that you're passing in. If the property has not been initialized, perhaps you havn't created the command yet? Or perhaps the datasource itself has not been initialized yet.
The weird thing with it is that it only happened occasionally and if i emptied my cache it would work fine.
So I just disable caching on that page and it seems to be working (at the moment)
Also added in some Try Catch statements and seems to be ok
Thanks for the help though
Jamie
Related
I'm aware that the NullReferenceException is pretty much the equivalent to the check engine light on a car but with this particular case I can't seem to pinpoint why its not working properly, I've never really messed with controls so I'm a bit unfamiliar in with the technicalities of it. What I have works, but I keep getting the exception when I run a trycatch around it. Here is what I have.
Dim TypeControl As Control
TypeControl = MaterialHeader_Edit1.FindControl("cboType")
DBTable = MaterialStuff.GetMaterial(ID)
Using DBTable
If DBTable.Rows.Count > 0 Then
Try
CType(TypeControl, DropDownList).SelectedItem.Text = (DBTable.Rows(0).Item("MaterialTypeDescription").ToString)
Catch ex As NullReferenceException
trace.runAllErrorLogging(ex.ToString)
End Try
End If
A NullReferenceException doesn't have anything to do with "controls" specifically. It's just an indication that your code assumes an object exists when at runtime it doesn't exist. For example, if you do this:
TypeControl = MaterialHeader_Edit1.FindControl("cboType")
CType(TypeControl, DropDownList).SelectedItem.Text = ...
Then your code assumes that TypeControl has a value on the second line. If it doesn't, trying to use .SelectedItem will fail because TypeControl is null. So you're assuming that .FindControl() actually found something. It doesn't make that guarantee implicitly.
Instead of making this assumption, you should verify:
TypeControl = MaterialHeader_Edit1.FindControl("cboType")
If TypeControl Is Not Nothing Then
CType(TypeControl, DropDownList).SelectedItem.Text = ...
End If
That way the code only executes if there's a value that it can use. You can add an Else to handle the condition where no value is found. (Display an error? Log the error? Silently continue? It's up to you how the condition should be handled.)
There are two possible problems here:
1 - Does FindControl actually find the control you seek? Add a check in to make sure you are actually finding it:
Dim TypeControl As Control
TypeControl = MaterialHeader_Edit1.FindControl("cboType")
If TypeControl Is Nothing Then Debug.Writeline("Could not find control")
2 - The SelectedItem of the control could also be Nothing so you may need to add a check here:
Dim ddl = CType(TypeControl, DropDownList)
If ddl.SelectedItem Is Nothing Then Debug.Writeline("Could not find selectedItem")
I have an ASP ComboBox that is populated on page load with a list of information and a selected index is set. I want the user to be able to type a new value into the box and run a routine that saves that value.
So far, I've managed to set it so when you run the save routine it can detect the text of the box using;
cboFreeBody.SelectedItem.Text
If the box loads with 'arm' and I change it to 'leg', when I run my routine it grabs the new value and processes it, however if I delete 'arm' and leave it blank when I run the routine the above code returns 'arm', where I'd expect it to return ''.
I'm sorry if I haven't explained myself fully here, I'm rather new to ASP and VB.NET so I'm probably just splurting useless information here, but any help would be greatly appreciated.
I ma not sure but thats might help you..
If com_box.SelectedItem = vbEmpty Then
MsgBox("its empty")
End If
I use the isnullorwhitespace function usually.
if string.isnullorwhitespace(cboFreeBody.SelectedItem.Text) then
else
end if
I have been trying to post packing slip from code. I have tried several ways but unfortunately without success.
My code is below:
purchTable = PurchTable::find('PO0012555');
purchFormLetter = PurchFormLetter::construct(DocumentStatus::PackingSlip);
purchformLetter.getLast();
purchFormLetter.transDate(transDate);
numberSeq = NumberSeq::newGetNum(PurchParameters::numRefPurchPackingSlipId()).num();
purchFormLetter.update(purchTable,
"14",// numberSeq, //this is coming out blank
transDate,
PurchUpDate::All,
AccountOrder::None,
false,
false);
When I tried to execute, I was getting this error:
Inventory is closed for physical and financial transactions until
Do you have any idea? Any help will be appreciated.
Thanks
My guess: your transDate variable does not have a valid date.
Using the cross reference you see the error only occurs in the checkOpen method of the table InventClosing.
Feel free to add a breakpoint here!
The method will fail if called with a blank transaction date.
Are you posting to a closed period? What is transdate? Check (General Ledger>Setup>Periods>Periods)
Thanks to masters who tried to help me but I figured out my problem. There is no problem about my code or anywhere.
We are working on this project with another consulting company. Somehow, one of developer who works other company remarked (commented) transdate line at PurchFormLetter class without any information.
So, when I tried to set transdate value at "purchFormLetter.transDate(transDate)" line, PurchFormLetter could not able to set the value cause of remarked line.
I uncommented the line and the code worked like a charm.
I'm doing the Wicked Code implementation of SqlSiteMapProvider, except in VB.NET.
There's a few things with the code that are causing issues, and I don't understand how it is supposed to work the way it's written in the article. I've provided the code straight from the article provided below. I've pasted the code here for ease of viewing
First issue - the depedency is instantiated BEFORE (lines 134-137) the tree is created (151-160) - so as soon as you add the depedency to the http.cache (165-167), the OnSiteMapChanged event (242) fires immmediately - making the entire proccess run again - and this loops many times until finally something makes it stop. (i stepped through it and counted the code looping at least 20 times before I gave up on trying to guess when it hit last)
OK, so to fix this I just moved the code to the create the dependency to AFTER the tree is built, right before inserting to http.cache (so HasChanged property is false when adding to http.cache, and you don't get stuck in this psuedo-ifinite-loop).
I still have a problem though - every time a page loads, the BuildSiteMap() hits and line 121 checks if _root is not null - it seems it is never null after it is first built... this is good because I don't want to hit the DB each time. Now, I insert a record into the table... the OnSiteMapChanged event never fires. As I browse pages on the app, the sitemap does not reflect the newly inserted record - stepping through the code, I see that the check at line 121 is still causing the function to short circuit... The sitemap will only refresh if i re-start Visual Studio, which causes the private _root field to become null again, and re-builds the sitemap, reflecting the new changes.. (refreshing the browser or starting new browser instances does not work)...
EDIT: THE ISSUE STEMMED FROM A SILLY 'SET NOCOUNT ON' LINE IN THE TOP OF MY STORED PROC. APPARENTLY THIS BREAKS THE QUERY NOTIFICATION. It seems that this statement is seen as a result set and that the second, actual query statement invalidates the result set resulting in a notification. This was very hard to find and nowhere in the MSDN documentation until I added the comment. Hope this saves someone else the miser I went through!
THE ISSUE STEMMED FROM A SILLY 'SET NOCOUNT ON' LINE IN THE TOP OF MY STORED PROC. APPARENTLY THIS BREAKS THE QUERY NOTIFICATION. It seems that this statement is seen as a result set and that the second, actual query statement invalidates the result set resulting in a notification. This was very hard to find and nowhere in the MSDN documentation until I added the comment. Hope this saves someone else the miser I went through!
I have a weird problem where the "Failed to enable constraints. One or more rows contain values violating non-null, unique, or foreign-key constraints." error sometimes pops up when I am trying to build my project.
The line in question throwing the error was auto-generated code in the designer file for the dataset. To find out the offending table, I used the following code:
Try
Me.Adapter.Fill(dataTable) <--Breakpoint here on the offending line
Catch ex As Exception
For Each TRow As DataRow In dataTable.Rows
If TRow.HasErrors Then
Trace.Write(TRow.RowError)
End If
Next
End Try
Funnily enough, as soon as I run the project after putting in the above code and breakpoint, the error disappears. I assume this has something to do with the code being regenerated. All data is presented successfully, and the project compiles without errors.
However, this has happened often enough for me to frustrate me. Anybody know what might be causing the error and how I can isolate it?
What unique constraint are you placing on the datatable and have you verified that the data your passing in doesn't have any duplicates? If this is coming from a shared database perhaps someone else is modifying the data which could be causing the randomness.
Edit
If that code is exactly as what you have (And forgive me my vb.net is not as strong as my C#). Wouldn't it swallow the exception? In C# we need to rethrow the error.
Add a Trace.Write() right before you go into your for loop.
You are probably working with a typed dataset, or have some code configuration on it. Also you might be reading from one table, and then adding data from another.
In any of those cases, you really want to look into any inconsistencies between the schema. If it is a typed dataset / or configured in code, check its definition, and look for anything different from the sql table. If you are reading from 2 different tables, check the definition of both tables.
Figured it out finally!
The reason the breakpoint wasn't being hit was because the code in question was auto-generated, and had the attribute "DebuggerNonUserCodeAttribute". In addition, in my VS settings, I had set the debugger to "Just my code".
When I ran the code again, and the breakpoint wasn't hit, I noticed the breakpoint icon had changed to a warning. Hovering showed this:
"The breakpoint will currently not be hit. Breakpoints cannot be set in a method or class with the 'DebuggerNonUserCode' attribute when the debugger option 'Just My Code' is enabled."
Ouch!
Once I had removed the "Just My Code" debugging option, the breakpoint was hit, and I discovered that one of the rows had a NULL value in one of the columns which had a non-null constraint. Stupid ole' me!
You should use this code before you fill DataTable :
var dt = new System.DataTable.DataTable();
dt.Clear();
dt.Rows.Clear();
dt.Columns.Clear();