Skip to main content

How to insert data into access database using vb.net project.

Source Code : -


Imports System.Data.OleDb


Public Class UserControl1

    Dim pro As String

    Dim connstring As String

    Dim command As String

    Dim myconnection As OleDbConnection = New OleDbConnection



    Private Sub UserControl1_Load(sender As Object, e As EventArgs) Handles MyBase.Load


    End Sub


    Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click

        pro = "Provider = Microsoft.ACE.OLEDB.12.0;Data Source = C:\Users\91846\OneDrive\Documents\demo_project.accdb"

        connstring = pro

        myconnection.ConnectionString = connstring

        myconnection.Open()

        command = "insert into STUDENT([Stu_Name],[Stu_Marks],[Stu_Age]) values ('" & TextBox1.Text & "','" & TextBox2.Text & "','" & TextBox3.Text & "')"

        Dim cmd As OleDbCommand = New OleDbCommand(command, myconnection)

        cmd.Parameters.Add(New OleDbParameter("Stu_Name", CType(TextBox1.Text, String)))

        cmd.Parameters.Add(New OleDbParameter("Stu_Marks", CType(TextBox2.Text, String)))

        cmd.Parameters.Add(New OleDbParameter("Stu_Age", CType(TextBox3.Text, String)))


        MsgBox("Record Save successfully!!")


        Try

            cmd.ExecuteNonQuery()

            cmd.Dispose()

            myconnection.Close()

            TextBox1.Clear()

            TextBox2.Clear()

            TextBox3.Clear()

        Catch ex As Exception

            MsgBox(ex.Message)

        End Try

    End Sub

End Class


Comments

Popular posts from this blog

Remove specific item from Recyclerview in android studio

For Full video click on below link :- https://youtu.be/sUz4fqeanjI?si=A8AqBWCgu-5NnBOJ Working with the activity_main.xml file. Navigate to the   app > res > layout > activity_main.xml  and add the below code to that file. Below is the code for the   activity_main.xml   file.  <?xml version="1.0" encoding="utf-8"?> <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" xmlns:app="http://schemas.android.com/apk/res-auto" xmlns:tools="http://schemas.android.com/tools" android:layout_width="match_parent" android:layout_height="match_parent" tools:context=".MainActivity" android:orientation="vertical" android:background="@color/white"> <EditText android:layout_width="350dp" android:layout_height="50dp" android:inputType="text" android:id="@+id/coursenam...

Fingerprint Authentication in Android Studio Project

Implement the implementation : - implementation 'androidx.biometric:biometric:1.0.1' Working with the activity_main.xml file. Navigate to the   app > res > layout > activity_main.xml  and add the below code to that file. Below is the code for the   activity_main.xml   file. <?xml version="1.0" encoding="utf-8"?> <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" xmlns:tools="http://schemas.android.com/tools" android:layout_width="match_parent" android:layout_height="match_parent" android:gravity="center" android:orientation="vertical" tools:context=".MainActivity" android:background="@color/white"> <TextView android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="Welcome to the Boxcode!!" android:textSize=...

programming skills imp programs

Full course of c++ programming language Click here >  C++ programming language ===================================== 1. Write a program to display an average of 3 inputted numbers. a=int(input("Enter a : ")) b=int(input("Enter a : ")) c=int(input("Enter a : ")) avg=(a+b+c)/3 print(avg) ====================================== 2. Write a program to calculate simple interest for a given principle amount, rate of interest and no of years. p=float(input("Enter a P : ")) r=float(input("Enter a R : ")) n=float(input("Enter a N : ")) si=(p*r*n)/100 print("simple interest is ",si) ====================================== 3. Write a program to display area of triangle. base=float(input("Enter a base : ")) height=float(input("Enter a height : ")) area=base*height/2 print("Area of triangle is ",area) ====================================== 4. Write a program to calculate area of circle. r=float(input...