473,699 Members | 2,564 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

How to use a datagridview to add/update/edit rows

I've read what's available here, but can't seem to make this work right. I'm
experimenting with components on a form, although I'd rather create the
pieces & assemble them in code, but that's another issue entirely.

I have a table in sql2k with an autoincrement column as primary index. It
also has a changeDate column with a trigger that updates to current datetime
when any column other than itself is changed.

Made a new form, followed Cor's tip & used Data to add a datasource.
Attached the bindingsource to the grid. To save the data, I'm doing this:

Private Sub DataGridView1_R owLeave(ByVal sender As Object, ByVal e As _
System.Windows. Forms.DataGridV iewCellEventArg s) Handles
DataGridView1.R owLeave
Try
Me.Validate()
Me.MoveTicketCr ossReferenceBin dingSource.EndE dit()
Me.MoveTicketCr ossReferenceTab leAdapter.Updat e(Me.MyDataset. MoveTicketCross Reference)
Catch ex As Exception
End Try
end sub

I can now view & edit the data, most of the time. But,
- the trigger usually does not fire, although sometimes it updates every row
with an identical date.
- The grid does not refresh -- gotta exit & open it.
- The autoincrement field increments up every time you enter the (*) row &
leave it, resulting in gaps in the primary index.
- Me.MoveTicketCr ossReferenceBin dingSource.Curr ent is not recognized as a
property. I'd like to look at it to see whether certain things need to be
done.
Jul 28 '06 #1
1 7721
First off, I was struggling with entering a new row, and then updating
the database. Your code helped me fix that (RowLeave event). Thanks.
Regarding your issue, it sounds like you don't have a where clause in
your trigger that limits the date update to the current row. If all
rows are being updated to the current date, you need to limit the
update to the current row. For grid refresh, you'll need to trigger
this somehow in your form, I think. A refresh button perhaps. Or some
other form or control event that would trigger the refresh. Regarding
the autoincrement, I have a data grid view that is bound to a table
with an identity (autoincrement) column in a SQLExpress 2005 database.
I can click in the new row as much as I want, and event edit the
contents, but if I escape out, thereby canceling the insert, my
identity field does not increment. So that one I don't know.

JeremyGrand wrote:
I've read what's available here, but can't seem to make this work right. I'm
experimenting with components on a form, although I'd rather create the
pieces & assemble them in code, but that's another issue entirely.

I have a table in sql2k with an autoincrement column as primary index. It
also has a changeDate column with a trigger that updates to current datetime
when any column other than itself is changed.

Made a new form, followed Cor's tip & used Data to add a datasource.
Attached the bindingsource to the grid. To save the data, I'm doing this:

Private Sub DataGridView1_R owLeave(ByVal sender As Object, ByVal e As _
System.Windows. Forms.DataGridV iewCellEventArg s) Handles
DataGridView1.R owLeave
Try
Me.Validate()
Me.MoveTicketCr ossReferenceBin dingSource.EndE dit()
Me.MoveTicketCr ossReferenceTab leAdapter.Updat e(Me.MyDataset. MoveTicketCross Reference)
Catch ex As Exception
End Try
end sub

I can now view & edit the data, most of the time. But,
- the trigger usually does not fire, although sometimes it updates every row
with an identical date.
- The grid does not refresh -- gotta exit & open it.
- The autoincrement field increments up every time you enter the (*) row &
leave it, resulting in gaps in the primary index.
- Me.MoveTicketCr ossReferenceBin dingSource.Curr ent is not recognized as a
property. I'd like to look at it to see whether certain things need to be
done.
Aug 3 '06 #2

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

1
2235
by: P K | last post by:
I have a Datagridview. I only edit couple of columns. No new rows are added. I need to know the count of "rows" that were modified. how do I acheive this?
2
24548
by: bob | last post by:
Can anyone tell me the best way to update a dataset while it is being edited/viewed in the DataGridView control? Is this something that should be inserted into one of the grid's events? or should you update after closing the grid/form, etc.? Also, can you tell me the best book to buy that fully explains the DataGridView control? Thanks.
0
2311
by: schoultzy | last post by:
Hello Everyone, I have been trying to figure this one out for two days now. I have created a DataGridView which is populated by an ObjectDataSource. My problem occurs when I attempt to use the Edit feature of the DataGridView. I have set several of the BoundField elements of the DataGridView to ReadOnly="True". When I attempt to use the Edit feature to UPDATE the rows in the DataGridView I get a System.NullReferenceException for...
3
16693
by: Bob | last post by:
Hi, FrameWork 2.0 Quick and dirty job so I thought I would do it all on the UI as quick and easy as possible. I got the datagridview to display my Access databaseview by using the Datasources and dragging the exposed view onto the datagrid as per the help instructions I can't get edits to go back to the database. I have tried editing cells at the UI and also programatically. With a UI edit the pencil comes up and goes away when I move...
3
7794
by: Prashwee | last post by:
Hello All In my windows application I am using DataGridView as my grid control. I populated let's say 10 rows of data and modified 3 random rows. I need to put some sort of Edit Marker in the row header. This can be an image. Please any one share a code for this implementation. If i were to save this records, how can I trap those 3 modified rows without going throgh the whole row set?
4
21298
by: Hexman | last post by:
Hello All, I'd like to find out the best way to add a cb column to a dgv and process efficiently. I see at least two ways of doing it. ------------------------------- 1) Add a cb to the dgv, iterate thru the dgv and update the bound fields if the cb has been checked. Then do the update and accept changes. How do I access the cb and its checked status? How to iterate thru dgv? Dim cbSelCol As New DataGridViewCheckBoxColumn
5
7150
by: DanThMan | last post by:
The situation: * I have a ButtonColumn in a DataGridView. * When the user preses one of the buttons, a dialog appears. * Based on what the user selects in the dialog, data is entered programmatically into the the underlying cell (i.e., I'm setting Value property of the cell based on user input, but the user is not directly entering any data). The problem:
4
4859
by: =?Utf-8?B?UmljaA==?= | last post by:
On a form - I have a datagridview which is docked to the entire form. The datagridview allows users to Delete and/or Add Rows. On the Form_Load event I Fill the datagridview source table with a sql DataAdapter (da) da.SelectCommand.CommandText = "Select * from Servertbl1" da.Fill(ds, "tbl1") so far, so good. If I add a row to the datagridview I use the following sqlDataAdapter code to update the server table - which works OK when...
15
1946
by: javatech007 | last post by:
I am creating a bank customer's details application. The information is stored on a Microsoft Access file and I was able to make the information appear on my VB application through text boxes and a DataGridView but I am not able to save,edit or delete records. Does anybody have any ideas. Below is my code. Public Class frmCustomerDetails Dim objDS As New DataSet Dim rowIndex As Integer = 0 Dim objConn As String =...
6
2844
by: Miro | last post by:
Sorry for the cross post. I am stuck. I have a datagridview for poker rounds. Basically there are 3 columns in this datagridview. "Round" "SmallBlind" "BigBlind" I have an issue when I tab through the new row being added. It does not 'Add' that row, nor setup the 'next blank add row' so I can continue to tab
0
8691
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
9180
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
9038
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
8920
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
7755
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
0
5877
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
4633
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
2
2351
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
2012
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.