Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
?
Solved

Searching SQL index with windows form (VB.net)

Posted on 2004-08-15
6
Medium Priority
?
235 Views
Last Modified: 2010-04-23
I'm currenty design one interface with CustomerID searching in SQL database, and i've already done the connection, which works on adding rows and deleting rows. i want the codes which can search the customerID successfully and link to another windows form. I need this question solve urgently, Please reply as soon as possible.
0
Comment
Question by:Dummies
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 3
  • 3
6 Comments
 
LVL 37

Expert Comment

by:gregoryyoung
ID: 11805293
well without knowing more details on your table structure and code this is kind of a vague question.

Basically you are just going to issue sql statements to return a set of customers

SELECT * FROM CUSTOMERS WHERE NAME LIKE 'Jo%'

would return customers name John Joe etc

you would then bind the result set to a grid etc and allow the user to select the customer they want, then you would instantiate a form for that customer ...
0
 

Author Comment

by:Dummies
ID: 11805316
I'm ok with the SQL statement, i just want the VB.net source code, uhhmm.. i just cant figure out how the code is, just like a basic searching query.... like a text box... and a button , when i fill in the customerID in the text box, after i click on button , the result will return.
0
 
LVL 37

Expert Comment

by:gregoryyoung
ID: 11805323
http://www.codeproject.com/vb/net/grid101.asp is a good tutorial on the datagrid control.
0
What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

 

Author Comment

by:Dummies
ID: 11805329
Here's what i get from MSDN library .. but it just come with ADD,EDIT,DELETE, and with FIXED only DATA, i want a searching... with user key-in

Imports System
Imports System.Data
Imports System.Data.SqlClient

Module Module1

    Sub Main()
        Dim sConnectionString As String
        ' Modify the following code to correctly connect to your SQL Server.
        sConnectionString = "Password=StrongPassword;User ID=UserName;" & _
                            "Initial Catalog=pubs;" & _
                            "Data Source=(local)"

        Dim objConn As New SqlConnection(sConnectionString)
        objConn.Open()

        ' Create an instance of a DataAdapter.
        Dim daAuthors As _
            New SqlDataAdapter("Select * From Authors", objConn)

        ' Create an instance of a DataSet, and retrieve data from the Authors table.
        Dim dsPubs As New DataSet("Pubs")
        daAuthors.FillSchema(dsPubs, SchemaType.Source, "Authors")
        daAuthors.Fill(dsPubs, "Authors")

        '*****************
        'BEGIN ADD CODE
        ' Create a new instance of a DataTable
        Dim tblAuthors As DataTable
        tblAuthors = dsPubs.Tables("Authors")

        Dim drCurrent As DataRow
        ' Obtain a new DataRow object from the DataTable.
        drCurrent = tblAuthors.NewRow()

        ' Set the DataRow field values as necessary.
        drCurrent("au_id") = "993-21-3427"
        drCurrent("au_fname") = "George"
        drCurrent("au_lname") = "Johnson"
        drCurrent("phone") = "800 226-0752"
        drCurrent("address") = "1956 Arlington Pl."
        drCurrent("city") = "Winnipeg"
        drCurrent("state") = "MB"
        drCurrent("contract") = 1

        'Pass that new object into the Add method of the DataTable.Rows collection.
        tblAuthors.Rows.Add(drCurrent)
        MsgBox("Add was successful.")

        'END ADD CODE    
        '*****************
        'BEGIN EDIT CODE

        drCurrent = tblAuthors.Rows.Find("213-46-8915")
        drCurrent.BeginEdit()
        drCurrent("phone") = "342" & drCurrent("phone").ToString.Substring(3)
        drCurrent.EndEdit()
        MsgBox("Record edited successfully")

        'END EDIT CODE  
        '*****************
        'BEGIN SEND CHANGES TO SQL SERVER

        Dim objCommandBuilder As New SqlCommandBuilder(daAuthors)
        daAuthors.Update(dsPubs, "Authors"),
        MsgBox("SQL Server updated successfully" & chr(13) & "Check Server explorer to see changes")

        ' END SEND CHANGES TO SQL SERVER
        '*****************
        'BEGIN DELETE CODE

        drCurrent = tblAuthors.Rows.Find("993-21-3427")
        drCurrent.Delete()
        MsgBox("Record deleted successfully")

        'END DELETE CODE
        '*****************
        ' CLEAN UP SQL SERVER
        daAuthors.Update(dsPubs, "Authors")
        MsgBox("SQL Server updated successfully" & Chr(13) & Chr(13) & "Check Server Explorer to see changes")
    End Sub

End Module
0
 
LVL 37

Accepted Solution

by:
gregoryyoung earned 900 total points
ID: 11805356
thats a pretty big change done you think ? Imports System
Imports System.Data
Imports System.Data.SqlClient

Module Module1

    Sub Main()
        Dim sConnectionString As String
        ' Modify the following code to correctly connect to your SQL Server.
        sConnectionString = "Password=StrongPassword;User ID=UserName;" & _
                            "Initial Catalog=pubs;" & _
                            "Data Source=(local)"

        Dim objConn As New SqlConnection(sConnectionString)
        objConn.Open()

        ' Create an instance of a DataAdapter.
        Dim daAuthors As _
            New SqlDataAdapter("Select * From Authors", objConn)

        ' Create an instance of a DataSet, and retrieve data from the Authors table.
        Dim dsPubs As New DataSet("Pubs")
        daAuthors.FillSchema(dsPubs, SchemaType.Source, "Authors")
        daAuthors.Fill(dsPubs, "Authors")

        '*****************
        'BEGIN ADD CODE
        ' Create a new instance of a DataTable
        Dim tblAuthors As DataTable
        tblAuthors = dsPubs.Tables("Authors")

        Dim drCurrent As DataRow
        ' Obtain a new DataRow object from the DataTable.
        drCurrent = tblAuthors.NewRow()

        ' Set the DataRow field values as necessary.
        drCurrent("au_id") = "993-21-3427"
        drCurrent("au_fname") = "George"
        drCurrent("au_lname") = "Johnson"
        drCurrent("phone") = "800 226-0752"
        drCurrent("address") = "1956 Arlington Pl."
        drCurrent("city") = "Winnipeg"
        drCurrent("state") = "MB"
        drCurrent("contract") = 1

        Dim dv As DataView = New DataView(tblAuthors)
        dv.RowFilter = "au_fname = 'George'"
        Dim i As Integer
        Dim msg As String = "Found " & dv.Count & " records named George "
        Dim ids As String = ""
        For i = 0 To dv.Count - 1
            ids &= dv(i)("au_id").ToString() & " "
        Next
        MessageBox.Show(Msg & " ids are " & ids)

        'Pass that new object into the Add method of the DataTable.Rows collection.
        tblAuthors.Rows.Add(drCurrent)
        MsgBox("Add was successful.")

        'END ADD CODE    
        '*****************
        'BEGIN EDIT CODE

        drCurrent = tblAuthors.Rows.Find("213-46-8915")
        drCurrent.BeginEdit()
        drCurrent("phone") = "342" & drCurrent("phone").ToString.Substring(3)
        drCurrent.EndEdit()
        MsgBox("Record edited successfully")

        'END EDIT CODE  
        '*****************
        'BEGIN SEND CHANGES TO SQL SERVER

        Dim objCommandBuilder As New SqlCommandBuilder(daAuthors)
        daAuthors.Update(dsPubs, "Authors"),
        MsgBox("SQL Server updated successfully" & Chr(13) & "Check Server explorer to see changes")

        ' END SEND CHANGES TO SQL SERVER
        '*****************
        'BEGIN DELETE CODE

        drCurrent = tblAuthors.Rows.Find("993-21-3427")
        drCurrent.Delete()
        MsgBox("Record deleted successfully")


        'END DELETE CODE
        '*****************
        ' CLEAN UP SQL SERVER
        daAuthors.Update(dsPubs, "Authors")
        MsgBox("SQL Server updated successfully" & Chr(13) & Chr(13) & "Check Server Explorer to see changes")
    End Sub

End Module

is an example of a quick search (can return multiple records) but I would take a look at the datagrid example for displaying your results.
0
 

Author Comment

by:Dummies
ID: 11807274
Well.. i've already solve my question by more simple way .. hehe.. but thx anyway for helping me ... keep it up....
0

Featured Post

Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

A while ago, I was working on a Windows Forms application and I needed a special label control with reflection (glass) effect to show some titles in a stylish way. I've always enjoyed working with graphics, but it's never too clever to re-invent …
It’s quite interesting for me as I worked with Excel using vb.net for some time. Here are some topics which I know want to share with others whom this might help. First of all if you are working with Excel then you need to Download the Following …
In a question here at Experts Exchange (https://www.experts-exchange.com/questions/29062564/Adobe-acrobat-reader-DC.html), a member asked how to create a signature in Adobe Acrobat Reader DC (the free Reader product, not the paid, full Acrobat produ…
This lesson discusses how to use a Mainform + Subforms in Microsoft Access to find and enter data for payments on orders. The sample data comes from a custom shop that builds and sells movable storage structures that are delivered to your property. …
Suggested Courses

618 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question