Programming for Everybody

Very simple Code insert button VBA without duplicate values in MS Access VBA with source code





Source Code in video

Dim dbs As DAO.Database

Dim rst As DAO.Recordset

Dim strsql As String

Set dbs = OpenDatabase("H:\products.accdb")

Set rst = dbs.OpenRecordset("Select product From Table1 Where product = '" & Me.Text0.Value & "' ")

If rst.RecordCount > 0 Then

MsgBox ("This Product exists before")

Else

strsql = "Insert Into Table1(product)Values( '" & Me.Text0.Value & "' )"

dbs.Execute (strsql)

MsgBox ("The product inserted successfully")

End If

rst.Close

dbs.Close


c# tutorial for beginners: How to store images update and delete in sql database with code





using System;

using System.Collections.Generic;

using System.ComponentModel;

using System.Data;

using System.Drawing;

using System.Linq;

using System.Text;

using System.Threading.Tasks;

using System.Windows.Forms;

using System.Data.SqlClient;

using System.IO;


namespace Images

{

    public partial class Form2 : Form

    {

        public Form2()

        {

            InitializeComponent();

        }

        SqlConnection conn = new SqlConnection("Data source=.;Initial catalog=images3;Integrated Security = true");

        SqlCommand cmd;

        private void button1_Click(object sender, EventArgs e)

        {

            openFileDialog1.Filter = "Select image(*.JpG; *.png; *.Gif)|*.JpG; *.png; *.Gif";

            if (openFileDialog1.ShowDialog()== DialogResult.OK)

            {

                pictureBox1.Image = Image.FromFile(openFileDialog1.FileName);

            }

        }


        private void button2_Click(object sender, EventArgs e)

        {

            cmd = new SqlCommand("Insert Into table1(name_image,image1)Values(@name_image,@image1)", conn);

            cmd.Parameters.AddWithValue("name_image", textBox1.Text);

            MemoryStream memstr = new MemoryStream();

            pictureBox1.Image.Save(memstr, pictureBox1.Image.RawFormat);

            cmd.Parameters.AddWithValue("image1", memstr.ToArray());

            conn.Open();

            cmd.ExecuteNonQuery();

            conn.Close();

            MessageBox.Show("Data Inserted Successfully");

            load_data();

        }

        private void load_data()

        {

            cmd = new SqlCommand("Select * from table1 order by id desc", conn);

            SqlDataAdapter da = new SqlDataAdapter();

            da.SelectCommand = cmd;

            DataTable dt = new DataTable();

            dt.Clear();

            da.Fill(dt);

            dataGridView1.RowTemplate.Height = 75;

            dataGridView1.DataSource = dt;

            DataGridViewImageColumn pic1 = new DataGridViewImageColumn();

            pic1 = (DataGridViewImageColumn)dataGridView1.Columns[2];

            pic1.ImageLayout = DataGridViewImageCellLayout.Stretch;

        }


        private void Form2_Load(object sender, EventArgs e)

        {

            load_data();

        }


        private void dataGridView1_Click(object sender, EventArgs e)

        {

            id1.Text = dataGridView1.CurrentRow.Cells[0].Value.ToString();

            textBox1.Text = dataGridView1.CurrentRow.Cells[1].Value.ToString();

            MemoryStream ms = new MemoryStream((byte[])dataGridView1.CurrentRow.Cells[2].Value);

            pictureBox1.Image = Image.FromStream(ms);

        }


        private void button3_Click(object sender, EventArgs e)

        {

            cmd = new SqlCommand("Update table1 Set name_image = @name_image,image1=@image1 Where id=@id", conn);

            cmd.Parameters.AddWithValue("name_image", textBox1.Text);

            MemoryStream memstr = new MemoryStream();

            pictureBox1.Image.Save(memstr, pictureBox1.Image.RawFormat);

            cmd.Parameters.AddWithValue("image1", memstr.ToArray());

            cmd.Parameters.AddWithValue("id", id1.Text);

            conn.Open();

            cmd.ExecuteNonQuery();

            conn.Close();

            load_data();

        }


        private void button4_Click(object sender, EventArgs e)

        {

            cmd = new SqlCommand("Delete from table1 where id=@id", conn);

            cmd.Parameters.AddWithValue("id", id1.Text);

            conn.Open();

            cmd.ExecuteNonQuery();

            conn.Close();

            load_data();

            pictureBox1.Image = null;

            textBox1.Text = "";

            id1.Text = "";

        }

    }

}


Code VB.Net SQL query combine two columns that contain different data type and display in ComboBox

 



Imports System.Data.SqlClient

Public Class Form1

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

        Dim conn As New SqlConnection("Data Source=.;Initial Catalog=products;integrated Security=true")

        'conn.Open()

        Dim cmd As New SqlCommand("Select id, '(' +  Cast(id As nvarchar(50))+ ')' + item_product  As products from names_products", conn)

        Dim da As New SqlDataAdapter(cmd)

        Dim dt As New DataTable

        da.Fill(dt)

        With ComboBox1

            .DataSource = dt

            .DisplayMember = "products"

            .ValueMember = "id"

            .Text = "Select Product"

        End With

    End Sub

End Class


How to filter subform using Combo box in MS access forms VBA

In this video, we'll show you how to filter a subform using a Combo box in MS access forms VBA. This method is useful if you want to display different data fields in a subform depending on the value of a selected field. We'll use the Combo box example to illustrate how to filter a subform using VBA. After watching this video, you'll be able to filter a subform using a Combo box in MS access forms VBA with ease! Subscribe to @programmingforeverybody https://www.youtube.com/@programmingforeverybody/?sub_confirmation=1

Excel VBA tutorial for beginners- How to create login form in Microsoft Excel VBA with source code



In this video, we'll learn how to create a login form in Microsoft Excel using VBA. We'll show you how to create a user login form with a show and hide password textbox. This tutorial is useful if you need to create a login form for your website or application. If you're a Microsoft Excel user, then this video is for you! In this video, we'll show you how to create a user login form using VBA. We'll show you how to create a user login form with a show and hide password textbox. This tutorial is useful if you need to create a login form for your website or application. So make sure to watch the video and learn how to create a login form with 
Subscribe to my channel to find everyday new information in programming and Computerr Science Subscribe to @programmingforeverybody
https://www.youtube.com/@programmingforeverybody/?sub_confirmation=1
Source Code:
Private Sub CheckBox1_Click()
If CheckBox1.Value = True Then
passtxt.PasswordChar = ""
Else
passtxt.PasswordChar = "*"
End If
End Sub

Private Sub CommandButton1_Click()
Dim ws As Worksheet
Set ws = ThisWorkbook.Sheets("Sheet2")
Dim i As Integer
For i = 1 To ws.UsedRange.Rows.Count
If usertxt.Value = ws.Cells(i, 1).Value And passtxt.Value = ws.Cells(i, 2).Value Then
UserForm1.lbl_user.Caption = Me.usertxt.Value
Unload Me
UserForm1.Show
Exit Sub
End If
Next
MsgBox ("Error username or password")
End Sub