I want to my search is a best
CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 12 of 12

Thread: I want to my search is a best

  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

  2. #2
    Join Date
    Jan 2013
    Posts
    7

    Exclamation Re: I want to my search is a best

    Where Your Answers ??????????

  3. #3
    DataMiser is offline Super Moderator Power Poster
    Join Date
    Jul 2008
    Location
    WV
    Posts
    4,860

    Re: I want to my search is a best

    Well you told us what you are trying to do and posted a bunch of code but you did not tell us what kind of problem you are having.

    What does it do now? What is it not doing? Have you stepped through the code to see that it is going through the way you expect it to?
    Always use [code][/code] tags when posting code.

  4. #4
    Join Date
    Jan 2013
    Posts
    7

    Re: I want to my search is a best

    I want to show me in each of TextBox The name according to near of my search is M ?? but is show to me is the first name only and if i click on the name in DataGridView Show in All of TextBox of names ??

    U can answer me fast

  5. #5
    DataMiser is offline Super Moderator Power Poster
    Join Date
    Jul 2008
    Location
    WV
    Posts
    4,860

    Re: I want to my search is a best

    Sorry but I can not understand what you are trying to say.
    Always use [code][/code] tags when posting code.

  6. #6
    Join Date
    Jan 2013
    Posts
    7

    Re: I want to my search is a best

    I want to see the names according to the name near from My search is E.X "M"

    then show from database names :
    Mariam
    Marian
    Mayer
    Ayman

    That's my want but the problem When is search for "M"
    Show me according by the id in database access .. but i don't want this >> and i have anther problem .. i want show me all the result each name in private textbox ...

    How To Make All I Want By Codes ???

  7. #7
    DataMiser is offline Super Moderator Power Poster
    Join Date
    Jul 2008
    Location
    WV
    Posts
    4,860

    Re: I want to my search is a best

    As near as I can tell you are binding a text box to a field, in such a case you will only get 1 value. For what you seem to want you would have to use unbound text boxes and write code to loop through the resulting data and update the text box values 1 by 1
    Always use [code][/code] tags when posting code.

  8. #8
    Join Date
    Jan 2013
    Posts
    7

    Re: I want to my search is a best

    yeah i want that >> plz write code quickly thank you

  9. #9
    DataMiser is offline Super Moderator Power Poster
    Join Date
    Jul 2008
    Location
    WV
    Posts
    4,860

    Re: I want to my search is a best

    Sorry, I am not here to write your code for you. You'll have to do that yourself, or at least give it a try. You can always ask questions along the way if you need help.
    Always use [code][/code] tags when posting code.

  10. #10
    Join Date
    Jan 2013
    Posts
    7

    Re: I want to my search is a best

    okay plz write the code quickly and thank you

  11. #11
    Join Date
    Jan 2013
    Posts
    7

    Re: I want to my search is a best

    then why i asked you for answer ..

  12. #12
    DataMiser is offline Super Moderator Power Poster
    Join Date
    Jul 2008
    Location
    WV
    Posts
    4,860

    Re: I want to my search is a best

    Answering a question is quite different than giving you the code, I don't mind helping people figure out a problem, I don't mind giving advice or even showing the correct way to write a few lines of code but when someone asks me to write the code for them the answer is always going to be no. That is your job.
    Always use [code][/code] tags when posting code.

Posting Permissions

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


Windows Mobile Development Center


Click Here to Expand Forum to Full Width

This is a CodeGuru survey question.


Featured


HTML5 Development Center