|
-
Apr 22nd, 2022, 06:50 PM
#1
Thread Starter
Fanatic Member
[RESOLVED] datagridview
I have a form containing the following datagridview DGV as shown below.
The DGV content displayed is from a database table (ACCESS). I would like to be able to input content directly into the last two columns. I had thought that this would be a simple process of setting some properties, but that appears not to be the case. Additionally, I have not even been able to find content that explains the process.
Can someone suggest what I am missing that I am unable to find an explanation of the process, assuming it exists? Or better still, explain the process?

The DGV is contained as part of a form. However, the DGV is completely independent of all else on the form.
-
Apr 22nd, 2022, 08:24 PM
#2
Thread Starter
Fanatic Member
Re: datagridview
OK, I have been looking and have a partial resolution, although not what I was wanting.
So I used the following code to load the data I wanted into the DGV. The DGV. The code is executed from the save button on the form
Code:
Private Sub UpdatePart()
'Assembly parameters
For i = 0 To dgvComponent.Rows.Count - 1
MasterBase.AddParam("@amount", dgvComponent.Rows(i).Cells(3).Value)
MasterBase.AddParam("@unit", dgvComponent.Rows(i).Cells(4).Value)
MasterBase.MasterBaseQuery("UPDATE adjAssembly " &
"SET colAmount=@amount,colUnit=@unit")
Next
End Sub
I then input the data into columns 3 and 4 in the DGV
Attachment 184700
Everything appeared to work well... except column 3 was updated to 75 for every record, instead of the two records being updated as displayed in the DGV.
I stepped through the code and it only went through 2 times. I believe the code is correct, but then I have been wrong so many times before.
-
Apr 22nd, 2022, 08:57 PM
#3
Re: datagridview
This code will update every record with the same value,
Code:
"UPDATE adjAssembly " &
"SET colAmount=@amount,colUnit=@unit"
You need to identify the record you want updated, usually there is a PrimaryKey
Code:
"UPDATE adjAssembly " &
"SET colAmount=@amount,colUnit=@unit WHERE yourIdField= @IdParam"
But if you are using a DataAdapter to retrieve the data then it would be easier to us the DataAdapter Update method.
-
Apr 22nd, 2022, 09:14 PM
#4
Re: datagridview
Any example that demonstrates how to retrieve and save data using a data adapter is relevant. Here's one I prepared earlier. You simply create a data adapter with the appropriate SelectCommand and UpdateCommand, or use a command builder to generate the UpdateCommand for you.
-
Apr 22nd, 2022, 09:50 PM
#5
Thread Starter
Fanatic Member
Re: datagridview
So basically, my cool method using the For/Next loop is bat dung! OK, I can accept that.
I have reviewed your suggestions and I think I can pull what I need to get what I need. Thanks.
Tags for this Thread
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|