negative number in my datagridview - database

I'm having problem in my datagridview.
I'm using vb 2008 and an access database. When I create a new record for my item the No column (primary key and autonumber in access) always shows a negative number.
How can I make that a positive number and it should follow the numbering in the datagridview. Here's a screen shot of that:

Your "No" column will start out with an AutoIncrementSeed of -1 and an AutoIncrementStep of -1. The DataSet isn't smart enough to start with the Max value of the "No" column, so you need to programatically set it.
Me.MyDataSet.MyDataTable.Columns("No").AutoIncrementSeed = _
Me.MyDataSet.MyDataTable.Max(Function(Row) Row.No) + 1
Me.MyDataSet.MyDataTable.Columns("No").AutoIncrementStep = 1
The first line above finds the maximum value of the No column and sets the AutoIncrementSeed to 1 above the maximum value. The second line just sets the IncrementStep to 1.
Keep in mind that the No column in the DataGridView may not correspond to the actual value that the database creates. When your data is committed, the database will create a new AutoNumber value, ignoring any other values you may pass in. There are some pitfalls to doing this if your users expect the No value to stay the same after committing the new entry.

Just open the dataset designer and look for the increment parameter (-1) for the applicable datagriview of the table concerned and change it to (+1). Then, rebuild or recompile your application and the problem will done with.

if its showing in negative
check the logic why its converted to negative
changing - to + dosent matters, but logic ??
CONVERT AS put condition as column1>=0

Related

Laravel - Saving INT to database turns negative

I'm saving some data to my database but there is one field which becomes negative when I save the data.
["invoice_id"]=> int(20210126075173)
This is taken from a var_dump() and is the number that I'm trying to save. This looks completely normal but when I look into the database I get the number
-1990019803
The thing is, when I run the code on my machine, it works like it's intended and saves the number as it should but when I do this on the actual server it returns that negative number. My local database is also a clone from the live database.
"Invoice_id" is a varchar field I tried changing it to INT or BIGINT but that makes no difference.
Why you change invoice_id from var_char field to int field? I think if it is varchar, you can add "" to save into database.
you can do several things to prevent this from happening:
make the database column a UNSIGNED INTEGER by using $table->unsignedInteger('column name');
Check the value before inserting to db with a if statement ( (int) ["invoice_id"] >= 0 ) ?? ["invoice_id"] * -1
The problem of difference between your local and remote server might be related to the database server(mysql,postgrs,...) version or system locale.I have not seen this before and have no idea what is causing it.
Make sure to validate the data before inserting it into database to prevent unwanted values (which takes you to second option)
Why are you looking to cast ["invoice_id"]=> int(20210126075173) to an int, when it seems like you're already giving it an integer?
You could try:
["invoice_id"]=> 20210126075173
or if you're casting a string to an int:
["invoice_id"]=> int() '20210126075173'

MS ACCESS Report - Using CODE to change a value in a field from an OPTION Group to a different value

I have a report in ACCESS that Is based on a query of a table populated by a form with an Option group. ( to try to explain this better - Table is inspector qualifications, the query pulls all of the qualifications for the inspector, the qualifications are selected via option group on a form that populates the fields of the inspector qualification table.) Of course, the choices are stored as numeric values, "1, 2, 3 or 4" in the table, but 4 actually designates a N/A or NONE. Since everything is already built out this way, I am trying to write a code that will run when the report is generated (or opened,) that will take the "4" value entered (if the field equals that) and change it to a Null value /blank in the report - not in the query or table. I still want this report to generate everything else as is - show all records - just change the value if that particular option is the one shown in that field for that particular record.
Anyone know of a good way to do this? Any help would be GREATLY appreciated!!!!
You would just place an 'IIF' in the query that tests for the value you want to change, then either changes it to something else, or retains the original value. The below will test field 'Nbr1' for the presence of a 4, and if found, change it to 'N/A', otherwise it stays the same.
Note! You will need to change the control source in the report to reflect the name you provide (i.e. 'MyChange') because you can't keep the original name.
SELECT Table1.ID, Table1.EMPID, Table1.TestResult,
IIf([Nbr1]=4,"N/A",[Nbr1]) AS MyChange, Table1.Nbr2
FROM Table1;

Copy data from SQL Server to Excel "NULL" instead of blank NUMBERS

I copy data from a SQL Server result set and paste it into an Excel spreadsheet. The NULL values need to appear as blanks in Excel, but the default behavior is to show the word, "NULL". For text fields, I can apply ISNULL([field],'') in the original query. But what about numeric fields? I don't want it to be 0, it needs to be blank. Is there a query based solution? I keep forgetting to do find and replace.
This is more of a comment but do to low rep, i'll post as an answer. Excel will not show a blank by default for a number value when pasted into the worksheet. It will interpret (correctly) a blank data point as 0. Since you are willing to find and replace 0s with null values, it seems this is for presentation purposes. If that is the case, I'd suggest conditional formatting. Set when the cell's value = 0 make the text white. if you are applying any mathematics to this column, the effect of a null cell or a 0 cell are the same, thus no impact to formulas/functions.

FileMaker Pro 13: How to get a summary variable to display an accurate total

I am working on a database of records that includes a step that only needs to be performed for some of the records (about a fourth of them). To keep track of which records needs the extra step, I created a boolean field with 0 for "doesn't need the step" and 1 for "needs the extra step" (these are assigned before importing the information into the database). There is also an option for the user to click a button and change the boolean from 0 to 1 (in case the record needs the extra step in the future).
The database also has a report feature that shows the total number of records that needs this extra step. I need this field to display the current total number of these records, so I have tried setting up a summary variable called Total PLQA that is defined to give the "Total of" and then the boolean variable (PLQA Bool). Somehow, I got the total to work once, but it seems that the reporting variable "Total PLQA" does not update when new records are added to the database or when users change the boolean value. Somehow, I need to get the variable to update whenever the report script is run and I can't figure out how to get it to work.
I have tried setting up a summary variable called Total PLQA that is
defined to give the "Total of"
That would be a summary field, not a variable.
it seems that the reporting variable "Total PLQA" does not update when
new records are added to the database or when users change the boolean
value.
A summary field always displays the summary value for the current found set (unless you place it in a sub-summary part, where it will display the sub-summary value for each sorted group).
Make sure your report layout is based on the same table where the summary field is defined, and that the summary field's instance placed on the layout is coming from the same table occurrence.
Note also that:
After import, only the imported/updated records will be found;
If you modify the Boolean field, you must commit the record before you will see the summary field reflect the change.

How do I get the Proper Item in a Delphi DBLookupComboBox to be Selected

I have a DBLookupComboBox that is wired to a database query. That part is working fine. When I run the program the DBLookupComboBox is populated with the results of the query. I'd like to to see the DBLookupComboBox populated with the first item "Please Select" when the program first runs or when a new item action is initiated. (See below image)
Also, if I'm loading a previously saved database record that had selected Index 2 "Quick Elimination" how would I get the DBLookupComboBox to display that selected entry?
Yes, "Please Select" is index 0 and it is retreived as part of the query.
You could try this (I know you've probably solved it by now, as you asked over 2 years ago), but in case anyone else was interested...
dbluLookup.KeyValue := dbluLookup.ListSource.DataSet.FieldByName(dbluLookup.KeyField).Value;
That simply sets KeyValue to the first record in the ListSource dataset, which should be the row 'Please Select'.
My guess would be that the value of the underlying table field is NULL rather than zero, which tells the DBComboBox that no value has yet been selected and it displays accordingly.
If the value in the table were zero, I thinkg the text in the edit field of the combo would be selected to indicate that, but I may recall this incorrectly.
Anyway, just check for Field1.IsNull (or IsEmpty) and then set it to zero. It does mean that you can no longer distinguish between an "unknown value" (NULL) and "no selected value" (zero), unless you prevent the zero value from making it back into the table...
One way of doing this would be to add 'Please select' to the underlying table from which you are selecting, where the key to this tuple would be 0. Then when you display the combobox and the value of the connected field is 0, 'Please select' would be displayed. Of course, you have to make sure that this value is never selected!
The DBLookupComboBox displays by default the ListField(s) whose KeyField in the ListSource matches the DataField in the DataSource. So, to ensure to display some value for the DataField being NULL, you have to provide a KeyField of NULL in the ListSource. But one could imagine not wanting a NULL value in the underlaying table associated to the ListSource.
One way to circumvent this is to add the NULL value to the dataset behind the ListSource with a UNION SELECT. That should work just fine, since that dataset does not have to be editable.
Now, to assure this special dataset is only available when you are adding a new record to the dataset associated to the DataSource, manage the query for ListSource.DataSet in DataSource.OnStateChange. When DataSource.State = dsInsert, then update ListSource.DataSet.
Modification for Steve Childs answer in TwwDBLookupCombo, InfoPower component
cboFilterTravel1.LookupValue := cboFilterTravel1.LookupTable.FieldByName(cboFilterTravel1.LookupField).Value;
Thanks Steve It's works for me

Resources