We help IT Professionals succeed at work.

VB 2008  - Delete all DataGridView records at one time

ljcor
ljcor asked
on
Medium Priority
240 Views
Last Modified: 2012-08-13
I am not sure how to delete all of the records that appear in the DataGridView at one time.  I do want them to be deleted from the table and the database.
Comment
Watch Question

CERTIFIED EXPERT

Commented:
CERTIFIED EXPERT
Commented:
Unlock this solution and get a sample of our free trial.
(No credit card required)
UNLOCK SOLUTION

Author

Commented:
I should have been more specific (for sure!):  I want to delete all of the data from a SqlServer DB.  I want to do this when a user clicks a button.

Author

Commented:
OK, that looks pretty much like what I need.  Can you tell me what  BuildDataList()  does?
CERTIFIED EXPERT

Commented:
@ ljcor:
 BuildDataList() is another call which populates datagrid like as under :

Sub BuildDataList ()
        Dim DBConn As MySqlConnection
        Dim DBCommand As MySqlDataAdapter
        Dim DSPageData as New DataSet
        DBConn = New SqlConnection(strConnection)
        DBCommand = New SqlDataAdapter ("Select * From Employee " & "Order By LastName,_ firstName",  DBConn)
        DBCommand.Fill(DSPageData, "Employee")
        dgEmps.DataSource = DSPageData.Tables("Employee").DefaultView
        dgEmps.DataBind()
End Sub

Thanks for the points.

Bm Keshav


Author

Commented:
Thanks for that additional info.  It does cause me to ask one more question: Does that function fetch ALL fields in the table or ONLY those displayed in the grid?  I assume the latter but I didn't know such a function even existed.

Author

Commented:
Or is this a function you created and not a system function?  I ask because I cannot find any reference to anything by that name in the reference sources.
CERTIFIED EXPERT

Commented:
Builddatalist is not a system function, its a you can say a function/class or procedure designed by me in our asp.net page to retrieve all data from employee table. You can see sql used in following line
DBCommand = New SqlDataAdapter ("Select * From Employee " & "Order By LastName,_ firstName",  DBConn)
is extracting all fields and all data from employee table. You can put sql a/c to your req. i mean your desired field/data aswell.
You can change like this :
DBCommand = New SqlDataAdapter ("Select field1,field2 From Employee where your creatary", DBConn)

Bm Keshav

Author

Commented:
Thanks very much for your help and instruction.
Unlock the solution to this question.
Thanks for using Experts Exchange.

Please provide your email to receive a sample view!

*This site is protected by reCAPTCHA and the Google Privacy Policy and Terms of Service apply.

OR

Please enter a first name

Please enter a last name

8+ characters (letters, numbers, and a symbol)

By clicking, you agree to the Terms of Use and Privacy Policy.