Click here to Skip to main content
15,888,984 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
This is how i add the row to dgv

SQL
Insert into table (Name, AddDate) values ('" & Name & "', '" & Date.Now & "')"

And after adding it i refresh the dgv

SQL
("Select * from table")
        Form1.DGV.DataSource = SQLDataset1.Tables(0)



Code for update

SQL
("Update table Set Name='" & txtT.Text & "' , DateEdit='" & Date.Now & "' Where Town= '" & txtT.Text & "'")


Working in visual studio 2013 VB.net and using local .mdf database
Posted
Comments
Richard Deeming 16-Apr-15 8:34am    
Your code is vulnerable to SQL Injection[^].

NEVER use string concatenation to build a SQL query. ALWAYS use a parameterized query.
Michael_Davies 17-Apr-15 16:56pm    
Set the selected row to the one you want, if it is the last row then:

dgv.Rows(dgv.Rows.Count - 1).Selected = True

Might be -2 as the last visible row is a place holder for a new record.

Otherwise remember a cell value (usually an auto increment) that makes the row unique and walk the rows till you find it and then make that row selected.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900