CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 12 of 12

Threaded View

  1. #1
    Join Date
    Jan 2013
    Posts
    7

    I want to my search is a best

    I did make an form to show a names saved in db Access .. and i did make an connection from v.b to access .. & in this object a form special for the search for these name ... and i have in db these names :
    Mayer
    Ayman
    Mariam
    Marian

    And i want to search about "M" .. My question is How to search for " M" show to me all name have a "M" in first or last or between the Characters ??? Thank You All

    I have the pic to c what i talking about .....

    and this the code :
    Code:
    Imports System.Data
    Imports System.Data.OleDb
    Public Class searchform
    Dim main As New Mainform
    Dim connectionstring As String = "Provider=Microsoft.Jet.OLEDB.4.0;" & "Data Source =" & Application.StartupPath & "\data1.mdb"
    Dim newconnection As New OleDbConnection(Connectionstring)
    Dim DataSet1 As New DataSet
    Dim SQLstr As String
    Dim m As String
    Dim DataAdapter1 As New OleDbDataAdapter(SQLstr, newconnection)
    Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
             Static m As Integer = 0
             If TextBox1.Text = Trim("") Then
                     Exit Sub
             ElseIf RadioButton7.Checked = True Then
                     ExactSearch()
             ElseIf RadioButton6.Checked = True Then
                     GeneralSearch()
             End If
             newconnection.Open()
             Dim DataAdapter1 As New OleDbDataAdapter(SQLstr, newconnection)
             DataAdapter1.Fill(DataSet1, "TableA")
             newconnection.Close()
             TextBox2.DataBindings.Add("Text", DataSet1, "TableA.name")
             TextBox3.DataBindings.Add("Text", DataSet1, "TableA.age")
             TextBox4.DataBindings.Add("Text", DataSet1, "TableA.sex")
             TextBox5.DataBindings.Add("Text", DataSet1, "TableA.mobile")
             TextBox6.DataBindings.Add("Text", DataSet1, "TableA.adress")
             DataGridView1.DataSource = DataSet1
             DataGridView1.DataMember = "TableA"
             DataGridView1.AllowDrop = True
             Button1.Enabled = False
             If Me.BindingContext(DataSet1, "TableA").Count = 0 Then
                     MsgBox("No Result, Please Try Again ")
                     Exit Sub
             End If
    
    End Sub
    Public Sub ExactSearch()
             If RadioButton1.Checked = True Then
                     SQLstr = "SELECT * FROM TableA WHERE name = '" & TextBox1.Text & "'"
             ElseIf RadioButton2.Checked = True Then
                     SQLstr = "SELECT * FROM TableA WHERE age = '" & TextBox1.Text & "'"
             ElseIf RadioButton3.Checked = True Then
                     SQLstr = "SELECT * FROM TableA WHERE sex = '" & TextBox1.Text & "'"
             ElseIf RadioButton4.Checked = True Then
                     SQLstr = "SELECT * FROM TableA WHERE mobile = '" & TextBox1.Text & "'"
             ElseIf RadioButton5.Checked = True Then
                     SQLstr = "SELECT * FROM TableA WHERE adress = '" & TextBox1.Text & "'"
             End If
    End Sub
    Public Sub GeneralSearch()
             If RadioButton1.Checked = True Then
                     SQLstr = "SELECT * FROM TableA WHERE name LIKE '%" & TextBox1.Text & "%'"
             ElseIf RadioButton2.Checked = True Then
                     SQLstr = "SELECT * FROM TableA WHERE age LIKE '%" & TextBox1.Text & "%'"
             ElseIf RadioButton3.Checked = True Then
                     SQLstr = "SELECT * FROM TableA WHERE sex LIKE '%" & TextBox1.Text & "%'"
             ElseIf RadioButton4.Checked = True Then
                     SQLstr = "SELECT * FROM TableA WHERE mobile LIKE '%" & TextBox1.Text & "%'"
             ElseIf RadioButton5.Checked = True Then
                     SQLstr = "SELECT * FROM TableA WHERE adress LIKE '%" & TextBox1.Text & "%'"
             End If
    End Sub
    Private Sub Button3_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button3.Click
             Me.Close()
             main.Show()
    End Sub
    Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button2.Click
             TextBox2.DataBindings.Clear()
             TextBox3.DataBindings.Clear()
             TextBox4.DataBindings.Clear()
             TextBox5.DataBindings.Clear()
             TextBox6.DataBindings.Clear()
             TextBox2.Text = ""
             TextBox3.Text = ""
             TextBox4.Text = ""
             TextBox5.Text = ""
             TextBox6.Text = ""
             Button1.Enabled = True
             SQLstr = ""
             DataSet1.Clear()
             Me.DataGridView1.DataSource = Nothing
    End Sub
    Private Sub searchform_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
             RadioButton1.Checked = True
             RadioButton6.Checked = True
    End Sub
    Private Sub Button4_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button4.Click
             Dim Obj1 As Object
             Obj1 = CreateObject("powerpoint.application")
             Obj1.Visible = True
             Obj1.Presentations.Open(FileName:="H:\تعديل\Ø£\أبارك الرب في كل Ø*ين.ppt")
    End Sub
    End Class
    Last edited by HanneSThEGreaT; January 18th, 2013 at 02:47 AM. Reason: Edited Font Size for better readability

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  





Click Here to Expand Forum to Full Width

Featured