Trying to update and insert using the same button in vb.net
Trying to update and insert using the same button in vb.net
(OP)
I have created a program where the user enters a release number and retrieve the data to a DatagridView connecting to a IBM db2 database. The options the users currently have is: Clear, Retrieve, Validate, and Update. The issue I am having is if the record is not in the database it doesn't update. I need to find a way to insert records that are not in the table and update records that are in the database.
Here is an example below:
Here is the program with release number: 18851

In the database here is what is listed:

The database does not have column: 27-PRODWK, 70-SCHPROD, 81-AB%, 82-ARM%, 83-SHAFT%, 84-FIT%, 85-HDW%, 86-FIN%, 87-WELDCMP
If the end users enter data in the datagrid it will not update because it hasn't been inserted yet.(This is the issue)
Can you help with this?
Here is an example below:
Here is the program with release number: 18851

In the database here is what is listed:

The database does not have column: 27-PRODWK, 70-SCHPROD, 81-AB%, 82-ARM%, 83-SHAFT%, 84-FIT%, 85-HDW%, 86-FIN%, 87-WELDCMP
If the end users enter data in the datagrid it will not update because it hasn't been inserted yet.(This is the issue)
Can you help with this?
RE: Trying to update and insert using the same button in vb.net
so, where do you want to save the data from these columns in the datagrid?
At the beginning of your Update logic, check if you have any record(s) to update. Simple SELECT statement will do it. If you have a record(s) coming back - do the Update, if not - do the Insert.
---- Andy
"Hmm...they have the internet on computers now"--Homer Simpson
RE: Trying to update and insert using the same button in vb.net
CODE -->
CODE -->
I have a private sub that calls the update query
CODE -->
This works for the update, but how do I include the insert part?
Insert query:
CODE -->
RE: Trying to update and insert using the same button in vb.net
CODE
---- Andy
"Hmm...they have the internet on computers now"--Homer Simpson
RE: Trying to update and insert using the same button in vb.net
CODE -->
I get an error: (local Variable) strRelease As String
Variable 'strRelease' is used before it has been assigned a value. A null reference exception could result at runtime.
RE: Trying to update and insert using the same button in vb.net
strRelease = “XYZ”
Second small problems – it is the same with other variables, as sqlStr, sqlStr1, sqlStr2, … sqlStr11
The biggest problem – what are you trying to achieve with this statement:
If Not ("Select * from jobscopedb.ppusrfs where search_key_uf= '" + strRelease + "'") Then
The above will ALWAYS evaluate to TRUE, any (non empty) string will evaluate to TRUE
---- Andy
"Hmm...they have the internet on computers now"--Homer Simpson
RE: Trying to update and insert using the same button in vb.net
RE: Trying to update and insert using the same button in vb.net
But before ms901Boss gets to parametrized queries, he/she (?) needs to have correct syntax / logic in the code. IMO
---- Andy
"Hmm...they have the internet on computers now"--Homer Simpson
RE: Trying to update and insert using the same button in vb.net
CODE -->
This is inserting data into the database, but I need to some way combine the update and insert in one button. If the update didn't update the field then I need to insert the field in the database. How do I do that with the code I have provided?
RE: Trying to update and insert using the same button in vb.net
Code:
CODE -->
In the update sub I call insert if the fill was blank
CODE -->
Thanks everyone for your help.
RE: Trying to update and insert using the same button in vb.net
BTW - why are you using ADODB instead of native NET's ADO?
---- Andy
"Hmm...they have the internet on computers now"--Homer Simpson