in this post you can learn about the if Record exists in SQL Server Database.Sometimes we put by mistake the duplicate entry in our text box for insert to database. For that we need to use this query because it will inform me about same entry. Use the below coding as per video instruction.

Imports System.Data.SqlClient Imports System.Data.Sql Imports System.IO Public Class Form1 Dim cnoo As New SqlConnection("") Dim cmddd As New SqlCommand Dim dr As SqlDataAdapter Private Sub B_Save_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles B_Save.Click If T_number.Text = "" Then MessageBox.Show("Fill Number Box") Else cmddd.Connection = cnoo cmddd.CommandText = "SELECT * FROM Table1 WHERE number='" & T_number.Text & "'" Dim adapter As New SqlDataAdapter(cmddd) Dim table As New DataTable() adapter.Fill(table) If table.Rows.Count() > 0 Then MessageBox.Show("Data Already Available! Go to Search Then Update") Else ' Type here your insert code End If End If End Sub
 
Top