I wrote the following code for inserting the value in table company_db & database is Company_DB but the value are not inserted into the table table shows null values the code is below:
Imports System.Data.OleDb
Imports System.Data.OleDb.OleDbConnection
Imports System.Data.OleDb.OleDbCommand
Public Class Newcompany
Inherits System.Windows.Forms.Form
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
Dim con As OleDbConnection = New OleDbConnection("Provider=Microsoft.ACE.OLEDB.12.0;Data Source=E:\New Folder\WindowsApplication1\WindowsApplication1\CompanyDB.accdb")
con.Open()
Dim cmd As OleDbCommand = New OleDbCommand("INSERT INTO company_db(comp_name, own_name, comp_add, telno, mo_no) VALUES (' " & Me.TextBox1.Text & " ',' " & Me.TextBox2.Text & " ',' " & Me.TextBox3.Text & " '," & Me.TextBox4.Text & "," & Me.TextBox5.Text & ") ", con)
If String.IsNullOrEmpty(Me.TextBox1.Text.ToString()) = True Then
MessageBox.Show("Enter company name")
ElseIf String.IsNullOrEmpty(Me.TextBox2.Text.ToString()) = True Then
MessageBox.Show("Enter owner name")
ElseIf String.IsNullOrEmpty(Me.TextBox3.Text.ToString()) = True Then
MessageBox.Show("Enter company address")
ElseIf String.IsNullOrEmpty(Me.TextBox5.Text.ToString()) = True Then
MessageBox.Show("Enter Mob.")
cmd.ExecuteNonQuery()
MessageBox.Show("Company Details Entered")
End If
TextBox1.Clear()
TextBox2.Clear()
TextBox3.Clear()
TextBox4.Clear()
TextBox5.Clear()
con.Close()
End Sub