Imports System.Data.OleDb
Imports System.Data.SqlClient
Public Class search
Dim conn As New SqlConnection
Dim da As New SqlDataAdapter
Dim strcon As String = "Data Source=.\SQLEXPRESS;AttachDbFilename=E:\Application\Abhi\Software\Software\Vansh.mdf;Integrated Security=True;User Instance=True"
Private Sub search_Load(sender As System.Object, e As System.EventArgs) Handles MyBase.Load
' con.ConnectionString = "Data Source=.\SQLEXPRESS;AttachDbFilename=E:\Application\Abhi\Software\Software\Vansh.mdf;Integrated Security=True;User Instance=True"
conn = New SqlConnection(strcon)
conn.Open()
loaddata()
' txtsearch.Enabled = False
' txtsearch.Text = "Student Id is auto number"
End Sub
Public Sub loaddata()
conn = New SqlConnection(strcon)
conn.Open()
Dim str As String = "Select * From Payment "
da = New SqlDataAdapter(str, conn)
Dim ds As New DataSet
da.Fill(ds, "Payment")
DataGridView1.DataSource = ds.Tables("Payment")
da.Dispose()
conn.Close()
End Sub
Private Sub Button3_Click(sender As System.Object, e As System.EventArgs) Handles Button3.Click
For Each txt In {txtmo, txtsearch}
txt.Clear()
Next
End Sub
Private Sub Button1_Click_1(sender As System.Object, e As System.EventArgs)
End Sub
Private Sub btnhome_Click(sender As System.Object, e As System.EventArgs) Handles btnhome.Click
Me.Hide()
Dim rd As New Home_Page
rd.Show()
End Sub
Private Sub txtsearch_TextChanged(sender As System.Object, e As System.EventArgs) Handles txtsearch.TextChanged
Try
conn = New SqlConnection(strcon)
conn.Open()
If txtsearch.Text = " " Then
loaddata()
Else
conn = New SqlConnection(strcon)
conn.Open()
Dim Str As String = "Select Date, Name, Amount from Payment where Name like '" + txtsearch.Text + "%' "
da = New SqlDataAdapter(Str, conn)
Dim ds As New DataSet
da.Fill(ds, "Payment")
DataGridView1.DataSource = ds.Tables("Payment")
da.Dispose()
conn.Close()
End If
Catch ex As Exception
MessageBox.Show(ex.Message)
End Try
End Sub
Private Sub DataGridView1_CellContentClick(sender As System.Object, e As System.Windows.Forms.DataGridViewCellEventArgs) Handles DataGridView1.CellContentClick
End Sub
Private Sub txtmo_TextChanged(sender As System.Object, e As System.EventArgs) Handles txtmo.TextChanged
Try
conn = New SqlConnection(strcon)
conn.Open()
If txtsearch.Text = " " Then
loaddata()
Else
conn = New SqlConnection(strcon)
conn.Open()
Dim Str As String = "Select Date, Name, Amount from Payment where Date like '" + txtmo.Text + "%' "
da = New SqlDataAdapter(Str, conn)
Dim ds As New DataSet
da.Fill(ds, "Payment")
DataGridView1.DataSource = ds.Tables("Payment")
da.Dispose()
conn.Close()
End If
Catch ex As Exception
MessageBox.Show(ex.Message)
End Try
End Sub
Private Sub DateTimePicker1_ValueChanged(sender As System.Object, e As System.EventArgs) Handles DateTimePicker1.ValueChanged
Try
conn = New SqlConnection(strcon)
conn.Open()
If txtsearch.Text = " " Then
loaddata()
Else
conn = New SqlConnection(strcon)
conn.Open()
Dim Str As String = "Select Date, Name, Amount from Payment where Date like '" + DateTimePicker1.Text + "%' "
da = New SqlDataAdapter(Str, conn)
Dim ds As New DataSet
da.Fill(ds, "Payment")
DataGridView1.DataSource = ds.Tables("Payment")
da.Dispose()
conn.Close()
End If
Catch ex As Exception
MessageBox.Show(ex.Message)
End Try
End Sub
Private Sub DataGridView2_CellContentClick(sender As System.Object, e As System.Windows.Forms.DataGridViewCellEventArgs) Handles DataGridView2.CellContentClick
End Sub
End Class