hi,
i have created Module.vb as database directory in the name of ConnDB.vb and Private sub ConnD()
i want to try search record which is showing in Datagridview1 and filtering rows ... i have tried but its seems to be error....
Note :
1. I want to Search CODE in txtsearch textbox
Please suggest basic search record sql statement
What I have tried:
Imports System.Data.OleDb
Public Class SongList
Dim cmd As OleDbCommand
Dim dr As OleDbDataReader
Dim sql As String
Dim dataFile As String
Dim ds As New DataSet
Dim con As New OleDbConnection
Dim da As New OleDb.OleDbDataAdapter
Private Sub Button16_Click(sender As Object, e As EventArgs) Handles Button16.Click
Song_Entry.Show()
Close()
End Sub
Public Sub Load()
ConnD()
Sql = "select * from SONGS"
cmd = New OleDbCommand(sql, conn)
dr = cmd.ExecuteReader()
DataGridView1.Rows.Clear()
Do While dr.Read = True
DataGridView1.Rows.Add(dr(0), dr(1), dr(2), dr(3), dr(4))
Loop
conn.Close()
End Sub
Private Sub SongList_Load(sender As Object, e As EventArgs) Handles MyBase.Load
Load()
Me.KeyPreview = True
End Sub
Private Sub Button15_Click(sender As Object, e As EventArgs) Handles Button15.Click
Close()
End Sub
Private Sub btnUpdate_Click(sender As Object, e As EventArgs) Handles btnUpdate.Click
Dim CODE, ETITLE, TTITLE, SONGT As String
CODE = txtCode.Text
ETITLE = txtET.Text
TTITLE = txtTT.Text
SONGT = RichTextBox1.Text
Try
sql = "update SONGS set ETITLE = ?,TTITLE = ?,SONGT = ? where CODE = ? "
ConnD()
cmd = New OleDbCommand(sql, conn)
cmd.Parameters.AddWithValue("ETITLE", ETITLE)
cmd.Parameters.AddWithValue("TTITLE", TTITLE)
cmd.Parameters.AddWithValue("SONGT", SONGT)
cmd.Parameters.AddWithValue("CODE", CODE)
cmd.ExecuteNonQuery()
Console.WriteLine(Command)
MessageBox.Show("Updated")
conn.Close()
txtCode.Enabled = False
txtET.Enabled = False
txtTT.Enabled = False
RichTextBox1.Enabled = False
Catch ex As Exception
MessageBox.Show(ex.Message)
End Try
End Sub
Private Sub DataGridView1_CellClick(sender As Object, e As DataGridViewCellEventArgs) Handles DataGridView1.CellClick
ConnD()
sql = "select * from SONGS where CODE = ?"
cmd = New OleDbCommand(sql, conn)
cmd.Parameters.AddWithValue("CODE", DataGridView1.CurrentRow.Cells(0).Value.ToString())
dr = cmd.ExecuteReader()
If (dr.Read) Then
txtCode.Text = dr(0).ToString
txtET.Text = dr(1).ToString
txtTT.Text = dr(2).ToString
RichTextBox1.Text = dr(3).ToString
End If
conn.Close()
End Sub
Private Sub Button8_Click(sender As Object, e As EventArgs) Handles Button8.Click
Dim CODE As String
CODE = txtCode.Text
Try
sql = "delete from SONGS where CODE = ? "
ConnD()
cmd = New OleDbCommand(sql, conn)
cmd.Parameters.AddWithValue("CODE", CODE)
cmd.ExecuteNonQuery()
Console.WriteLine(Command)
MessageBox.Show("Deleted")
Load()
conn.Close()
Catch ex As Exception
MessageBox.Show(ex.Message)
End Try
End Sub
Private Sub txtsearch_TextChanged(sender As Object, e As EventArgs) Handles txtsearch.TextChanged
End Sub
Private Sub DataGridView1_CellContentDoubleClick(sender As Object, e As DataGridViewCellEventArgs) Handles DataGridView1.CellContentDoubleClick
Dim form As New SongShow
form.RichTextBox1.Text = DataGridView1.CurrentRow.Cells(3).Value.ToString()
form.RichTextBox2.Text = DataGridView1.CurrentRow.Cells(3).Value.ToString()
form.RichTextBox3.Text = DataGridView1.CurrentRow.Cells(4).Value.ToString()
form.ShowDialog()
End Sub
Private Sub SongList_KeyDown(sender As Object, e As KeyEventArgs) Handles MyBase.KeyDown
If e.KeyCode = Keys.Escape Then
txtEsearch.Clear()
txtsearch.Clear()
txtTsearch.Clear()
txtsearch.Focus()
End If
End Sub
Private Sub Button10_Click(sender As Object, e As EventArgs) Handles Button10.Click
End Sub
Private Sub TextBox5_TextChanged(sender As Object, e As EventArgs) Handles txtEsearch.TextChanged
Dim selStart As Integer = txtEsearch.SelectionStart
txtEsearch.Text = txtEsearch.Text.ToUpper()
txtEsearch.SelectionStart = selStart
End Sub
Private Sub Button14_Click(sender As Object, e As EventArgs) Handles Button14.Click
txtCode.Enabled = True
txtET.Enabled = True
txtTT.Enabled = True
RichTextBox1.Enabled = True
End Sub
Private Sub DataGridView1_KeyDown(sender As Object, e As KeyEventArgs) Handles DataGridView1.KeyDown
If e.KeyCode = Keys.Enter Then
Dim form As New SongShow
form.RichTextBox1.Text = DataGridView1.CurrentRow.Cells(3).Value.ToString()
form.RichTextBox2.Text = DataGridView1.CurrentRow.Cells(3).Value.ToString()
form.RichTextBox3.Text = DataGridView1.CurrentRow.Cells(4).Value.ToString()
form.ShowDialog()
End If
End Sub
End Class