How to Save Data in the Database Using Visual Basic 2008 and SQL Server 2005
Submitted by janobe on Monday, August 1, 2016 - 09:53.
This time, I will show you how to save data in the database using Visual Basic 2008 and SQL Server 2005 Express Edition. Using this method, the data will be saved in the database and It will also display the data that you have been saved in the database to the Datagridview. See the step by step procedure below.
Step 3. Go to the code editior and declare all the classes that are needed.
Step 4. Go back to the design view, double-click the form and establish a connection between SQL Server 2005 Express Edition and Visual Basic 2008.
Step 5. Create a method for saving the data in the SQL Server Database.
Step 6. Go back to the design view, double-click a "Save" button and call the
For all students who need a programmer for your thesis system or anyone who needs a source code in any programming languages. You can contact me @ :
Email – [email protected]
Mobile No. – 09305235027 – TNT
Let's Begin:
Step 1. Create a database in the SQL Server 2005 Express Edition and name it "userdb". Step 2. Open Visual Basic 2008 and create a new windows form application. After that, Do the form just like this.
Reminder: Put "using System.Data.SqlClient;" above the namespace to access sql server library.
- Dim con As SqlConnection = New SqlConnection()
- Dim cmd As SqlCommand
- Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
- con.ConnectionString = "Data Source=.\SQLEXPRESS;Database=userdb;trusted_connection=true;"
- End Sub
- Private Sub SaveData(ByVal sql As String)
- Try
- con.Open()
- If con.State = ConnectionState.Open Then
- Dim result As Integer
- cmd = New SqlCommand
- With cmd
- .Connection = con
- .CommandText = sql
- result = .ExecuteNonQuery
- End With
- If result > 0 Then
- End If
- End If
- Catch ex As Exception
- Finally
- End Try
- End Sub
sub procedure
that you have created in the method.
- Private Sub btnSave_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnSave.Click
- Dim sql As String = "INSERT INTO tbluser (NAME,UNAME,PASS,UTYPE) VALUES ('" & txtName.Text & "','" & txtUsername.Text & "','" & txtPassword.Text & "','" & cboUtype.Text & "')"
- SaveData(sql)
- End Sub
Add new comment
- 178 views