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...

C++ programming language

                c++ is a general programming language and is widely used nowadays for competitive programming. It has imperative, object-oriented and generic programming features.C++ runs on lots of platforms like Windows, Linux, Unix, Mac etc.   ❖❖  C++ with oops ❖❖

7. Switch Statement in c++

 ❖ C++ switch Statement :-                Consider a situation in which, only one block of code needs to be executed among many blocks. This type of situation can be handled using nested if...else statement but, the better way of handling this type of problem is using switch...case statement.  Syntax of switch:-      Switch(expression) {            Case value1 : statement1;                       Break;             Case value2 : statement2;                      Break;             Default : default statements;  }               The expression is either an integer or a character in above syntax. If the expression matches constant in case, the relevant codes a...