Thank you All for your friendly help.
Hi theMethod,
Welcometo MSDN forums!
Here are four methods tomake one basicData Access application(Previous, Next, First. Last, Update,Delete,Insert, Select, Save) for you to check and follow.
Method 1:Update (Insert/Update/Delete) data back into SQL Server database via a DataGridView.
http://social.msdn.microsoft.com/forums/en-US/Vsexpressvb/thread/5980181e-f666-4f0a-ab50-c4ebecf96f02/
|
ImportsSystem.Data.SqlClient
|
|
|
|
PublicClassForm1
|
|
|
|
DimmyDAAsSqlDataAdapter
|
|
DimmyDataSetAsDataSet
|
|
PrivateSubForm1_Load(ByValsenderAsSystem.Object,ByValeAsSystem.EventArgs)HandlesMyBase.Load
|
|
DimconAsSqlConnection=NewSqlConnection("DataSource=.;IntegratedSecurity=True;AttachDbFilename=|DataDirectory|\SqlDatabase.mdf")
|
|
DimcmdAsSqlCommand=NewSqlCommand("SELECT*FROMTable1",con)
|
|
con.Open()
|
|
myDA=NewSqlDataAdapter(cmd)
|
|
'AutomaticallygeneratesDeleteCommand,UpdateCommandandInsertCommandforDataAdapterobject
|
|
DimbuilderAsSqlCommandBuilder=NewSqlCommandBuilder(myDA)
|
|
myDataSet=NewDataSet()
|
|
myDA.Fill(myDataSet,"MyTable")
|
|
DataGridView1.DataSource=myDataSet.Tables("MyTable").DefaultView
|
|
con.Close()
|
|
con=Nothing
|
|
EndSub
|
|
|
|
'SavedatafromDataGridViewintoDatabase
|
|
PrivateSubButton1_Click(ByValsenderAsSystem.Object,ByValeAsSystem.EventArgs)HandlesButton1.Click
|
|
Me.Validate()
|
|
Me.myDA.Update(Me.myDataSet.Tables("MyTable"))
|
|
Me.myDataSet.AcceptChanges()
|
|
EndSub
|
|
|
|
EndClass
|
|
Method 2.Using Data Wizard with a BindingNavigator control.
Please check the 11th post in this threadfor detailed walkthrough:
http://social.msdn.microsoft.com/forums/en-US/Vsexpressvb/thread/ff3f953b-da66-4f03-b4e4-981bab7d783b/
Method 3. UsingDataSet/DataTable/DataAdapter inVB.NET code
Please check the 12th post and 13th post in this threadfor detailed code sample.
http://social.msdn.microsoft.com/forums/en-US/Vsexpressvb/thread/ff3f953b-da66-4f03-b4e4-981bab7d783b/
Method 4.ExecuteSelect/Insert/Delete/Update T-SQL commandsin VB.NET code
Code sample: How toSelect/Insert/Delete/Updaterecords in MS Access databasein VB.NET
http://forums.msdn.microsoft.com/en-US/vbgeneral/thread/87913f28-992d-4705-963b-cb0ffa53d8dd/
Code sample: How toSelect/Insert/Delete/Updaterecords in SQL Serverdatabasein VB.NET
http://forums.msdn.microsoft.com/en-US/vbgeneral/thread/89e1067d-16e7-44e8-b12d-d78845bf255f/
Best regards,
Martin Xie
Please remember to mark the replies as answers if they help and unmark them if they provide no help.
Welcome to the All-In-One Code Framework! If you have any feedback, please tell us.