Mysql VB.NET: Hiding column from datagridview null exception error (column is not null) - mysql

I have a datagridview that is populated with the data I retrieved from the database (mysql)
When I try to hide the column or change the column header text, this exception was thrown:
Object reference not set to an instance of an object.
or
Index was out of range. Must be non-negative and less than the size of
the collection. Parameter name: index
with this simple code:
gridjobs.Columns(0).Visible = False
gridjobs.Columns("JOB_NO").HeaderText = "JOB NO."
I can tell you that the datagrid is not null, it was working before but suddenly this error popped up. I tried searching the net but still no luck in fixing this error. Everything is working, except this. Is there something wrong with my code?

based on google
Object reference not set to an instance of an object. exactly what it says, you are trying to use a null object as if it was a properly referenced object. ... Most of the time, when you try to assing value into object, and if the value is null, then this kind of exception occur.
This one is common sense here is your code.
gridjobs.Columns(0).Visible = False
gridjobs.Columns("JOB_NO").HeaderText = "JOB NO."
the first column is Visible = False then you assigned a header text? How can I assign a value in an Object that Invisible?
Just a wild guess.
and also why do u need to assign a header that will be visible = false also? anyway try this
gridjobs.Columns(0).Visible = False
gridjobs.Columns(0).HeaderText = "JOB NO."

Related

How to Load Data into Tool Strip Combobox from Database

Does a converted combobox from toolstrip menu cannot display data from database? I'm trying to populate my converted combobox but when i tried to use .datasource and .displaymember it doesnt show from suggested list of keywords, converted combobox doesn't seem to support Data Bindings.
I find your text a bit unclear and contradictary as for what is actually wrong and desired. Hopefully, here is what you're after.
You've already got the data as DataSet named dataset. Here, be aware, you're missing a ValueMember, so let's assume it's only a DisplayMember you're after.
All you need to do is following:
' ToolStripComboBox1.ComboBox.ValueMember = "ID" ' you'd use it, if you wanted a ValueMember
ToolStripComboBox1.ComboBox.DisplayMember = "name"
ToolStripComboBox1.ComboBox.DataSource = dataset.Tables(0)
If you want to select pre-defined item:
ToolStripComboBox1.ComboBox.SelectedIndex = 3
If you want to get selected item:
Dim StrSelected as String
StrSelected = ToolStripComboBox1.ComboBox.GetItemText(ToolStripComboBox1.ComboBox.SelectedItem)
If it's AutoComplete source giving you problems, you probably wan't to set:
ToolStripComboBox1.AutoCompleteSource = AutoCompleteSource.ListItems
But I get a feeling, that you're confused and you actually don't need anything related to AutoComplete, since you also set:
ToolStripComboBox1.AutoCompleteMode = AutoCompleteMode.None
...which is contradicting "show from suggested list of keywords". That's why I initially thought you're actually not seeing anything in your ComboBox, because you didn't provided DisplayMember and DataSource.
If you want to include a value member, first include it into SQL query:
SearchQuery = "select ID,name from pis.roles"
Then uncomment row above with Value member and it will be loaded (with no visible effect).

Handling and modifying the exception returned when a Google Sheets =query() returns #N/A

I have a query that runs on Google Sheets against a table where the user has separate input that can modify values in logic checks to a TRUE FALSE result on that table. It is possible that the user has a selection that returns all FALSE for a where statement within the query.
The output I get is #N/A, I want to be able to create an exception where I can identify that it's returning #N/A, and change the output to blank or "No results found".
My users are not very tech savvy, so I need it to be legible to someone without coding knowledge or experience.
Normally when I'm returned an error from a function in Google Sheets, or Excel for that matter, I use the =Iferror() function to control the output of an error exception. This does not seem to work, either because the function iferror was made with a scope that falls outside of =query, or because of some other behind the scenes structural problem.
FALSE, PIG, $5.50
FALSE, APPLE, $0.50
FALSE, CAR, $25.00
FALSE, HORSE, $20.00
I thought then maybe I could add an if() statement, and put the query in a logic statement checking for the value "N/A":
if(query(A:B,"select B where A =TRUE")="#N/A","No results found",(A:B,"select B where A = TRUE"))
This did not work. The value that was returned was "#N/A" still. So I thought maybe the value type of the exception wasn't technically a string value, so it wouldn't accept the value of a non-string #N/A to equal "#N/A", so I wrapped the first query in a concatenate() in an attempt to force it into a singular variable/cell value. I know this works in turning the query it runs into a singular string if it has results, but doing this:
if(concatenate(query(A:B,"select B where A =TRUE"))="#N/A","No results found",(A:B,"select B where A = TRUE"))
This still returns "#N/A"
I thought maybe the actual value it's throwing back is a NULL type value, and it has some clever behind the scenes shenanigans to make it display "#N/A" when the where function filters out all results. so I changed the parameter it's checking against in the if statement from "#N/A" to "" as follows:
=if(concatenate(query(lookup!Z2:AN,"select Z where AN = TRUE"))="","No results found",query(lookup!Z2:AN,"select Z where AN = TRUE"))
This still returns "#N/A"
I thought maybe the isblank() function would have some mechanism in it to find that it's blank, changing it to:
=if(ISBLANK(concatenate(query(lookup!Z2:AN,"select Z where AN = TRUE"))),"No results found",query(lookup!Z2:AN,"select Z where AN = TRUE"))
This also still returns "#N/A"
I'm at a loss. I'm expecting it to throw me the exception I'm qualifying: "No results found" but this never comes. Obviously, I don't understand the nature of how the =query() function is handling data on the back end of things. It must be doing something on a separate layer of operations or something, or have a totally different scope, but how am I supposed to figure out what that variable/process is?
Not just IFERROR?:
=iferror(query(A:B,"select B where A =TRUE"),"No results found")

Mystic MySql Laravel issue

I have gotten into an issue, which is kind of, what?
1. In my controller I get the input values from form.
2. I create row in database table and fill in the red values.
The problem is that one of these input values is an integer and when I put in DB table, its always 0, nothing else. I returned the just the issued value, its not 0.
The DB table column names are all correct, data type is also correct.
The weirdest part is that in other function (the same controller), I do the same from other input values, and it puts in the correct values, also the one with the same type... code is identical, but in one case it puts in zeros...
I am trying to add an integer value to DB table with
Projects::create([
'name'=>$name,
'region'=>$region,
'needs'=>$amount, <-the issued value
'ready'=>false
]);
I am 100% sure that this table has column "needs" and that the $amount variable is holding the correct value (not 0).
This has bean a real head cracker for few hours, and nothing, cant find anything that would solve this...
The code of retrieving Input data is:
$name = Input::get('name');
$region = Input::get('region');
$amount = Input::get('projectAmount');
Projects::create([
'name'=>$name,
'region'=>$region,
'needs'=>$amount,
'ready'=>false
]);

VBA functions not working, returns error

I have a problem that I have been trying to solve for a couple of days with MS Access and a VBA function.
To start I have a table as follows
Name = Team
fields are mostly text bases, unless stated otherwise
ID(autonumber primary key)
Non
Prenom
Location
TeamID (created by concatenting the Nom, Prenom and Location fields)
On my form I would like to extract the partial details entered into the Nom, Prenom, and Location fields. Then pass this back to the Database to enter into the TeamID field for the individual.
The extraction should take the form of
TeamID = mid(Location,0,4) & mid(Prenom,0,2) & mid(Nom,0,2à)
However I realise that I can't put this into the 'controle source' section of the properties for any field.
So after much searching I decided that I should use a function in a separate module (I do this concatenating quite often for creation of 'sensible' index values on a large number of my tables, I find the autonumber primary key not very user friendly, or self explanatory.
So in my database file I created a module (called getInfo) with the public function
Public Function getID() As String
Dim r As String
Dim i As String
i = "Twenty"
Below are some of the options I have tried....
'r = VBA.Strings.UCase$(String:=i) 'turning the value of i to uppercase
getID = r 'returns "TWENTY" as expected
or
'r = VBA.Strings.Mid$("TWENTY", 0, 2)
getID = r 'error and highlights above line?
or
'r = StrReverse(i)
getID= r 'again error and highlights above line
getID = VBA.Strings.Mid$(String:="TWENTY", Start:=0, Length:=2)
End Function
I then opent eh 'execution' window and run the function.
I seem to be only able to convert the value to upper or lower case, any searching or manipulation of the string just gives me a message bow with the following error
Execution Error '5'
argument or procedure call incorrect
(please bear with me I am working on a french terminal and so my translation of this error may not be very acurate).
However all the functions come up correctly when I type them, as do the parameters being passed. when I search the net the info is also the same
http://www.techonthenet.com/excel/formulas/index_vba.php
So I am lost as to where I am going wrong.
I guess I am not declaring the value of my variables correctly, but I can't see why.
This code doesn't work elsewhere (other terminals) either, so I'm sure it must be my error!
But what is it.
I feel that this is a reallybasic problem, but just can't get the function to work when manipulating a string.
Do I need to call this function from a sub only, and not directly, will this be the same on my form page?
I can create a minidatabase with just this code in if required.
You should not need the VBA.String namespace prefix, and the ArgName:= syntax is optional so long as you follow same-order rules for optional paramaters.
Mid$("TWENTY", 0, 2) fails because in VBA strings start at index 1, so Mid$("TWENTY", 1, 2) would return TW

Why am I getting "Invalid Cast" when using Linq to SQL?

I am a bit of a newbie when it comes to Linq to SQL but I hope you can help out. I've written the following Linq to SQL statement with Extension Methods:
Cedb.ClassEvents.Where(c => c.ClassID == 1).Select(c => c).Single()
Where Cedb is the Datacontext, ClassEvents is a table (for classes and events being held at a facility) and ClassID is a unique integer key.
This query runs fine in LinqPad (without Cedb). When it returns, it says that the return type is "ClassEvent". In Intellisense in Visual studio, it tells me that the return type of this query is ClassEvent (created in my data model). However, when I try to place the results in a variable:
var classEvent = Cedc.ClassEvents.Where(c.ClassID == 1).Select(c => c).Single();
then I get an error: InvalidCastException: Specified cast is not valid. The same thing happens if I use the "ClassEvent" class in place of the var. I'm new to this but this one seems like a true slam dunk rather than a bug. Is there something about the Single method that I don't know that is leading to the error? Any help would be appreciated!
Slace - and any other interested parties. The cause of the "Invalid Cast Exception" error was a change in the underlying data model. A smallint field had been changed to bit. Thus, when the system tried to map the query results onto the "ClassEvent" data structure, the conflict between the model (which had not been updated) and the data table emerged.
Nonetheless, I do appreciate the answer!
You don't need to do both a Select and a Single, in fact, you don't even need the Where, you can get away with (see http://msdn.microsoft.com/en-us/library/bb535118.aspx):
var classEvent = Cedc.ClassEvents.Single(c => c.ClassID == 1);
I'd also recommend against using Single unless you're 100% sure that the Func<T, bool> will always return a value, as if it doesn't return a value you will have an exception thrown. Better is using SingleOrDefault and doing a null check before interaction with the object (http://msdn.microsoft.com/en-us/library/bb549274.aspx)