[Webinar] Streamline your web hosting managementRegister Today

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 280
  • Last Modified:

Show Search Results In Windows Application Form

I'm new to programming/developing using vb.net in visual studio 2005 and wanted to get some general direction for accomplishing this.  I have a simple computer hardware inventory database I'm trying to create a windows based application for a few users to use for pulling information.

I have a search form with 4 option boxes for search criteria:  first name, last name, employee number, serial number (computer), and a search button.  I'm using a sql server db, and I'm just wondering where to start with creating the code behind for this search box.  Do I use a stored procedure?  I want to return all the information in the record like, Employee's name, location, number, computer, serial, etc...

Any help would be great!  Thanks in advance.
0
john8694
Asked:
john8694
  • 5
  • 3
1 Solution
 
Jorge PaulinoIT Pro/DeveloperCommented:
>> Do I use a stored procedure?
You don't have to use it.

Do you want to display in a listview or a datagridview ?
0
 
Jorge PaulinoIT Pro/DeveloperCommented:
Also do you have any code done it ? If so you can show what you have.
0
 
john8694Author Commented:
Hi Ipaulino, I guess I'd like to show in a listview to make it look a little better.  Is one view better or prfered over the other?  And I don't have any code attached yet to that form.  
0
The new generation of project management tools

With monday.com’s project management tool, you can see what everyone on your team is working in a single glance. Its intuitive dashboards are customizable, so you can create systems that work for you.

 
Jorge PaulinoIT Pro/DeveloperCommented:
Normally I do it this way

Inside a Module

        Public Function GetConnection() As SqlConnection
        Dim SqlServerName As String = "MYSERVER"
        Dim SqlServerDatabase As String = "myDB"
        Dim SqlServerLogin As String = "efw"
        Dim SqlServerPassword As String = "fwefw"

        Dim conn As SqlConnection

        Dim strConn As String = "Data Source=" & SqlServerName & ";Initial Catalog=" & SqlServerDatabase & ";User ID=" & SqlServerLogin & ";Password=" & SqlServerPassword & ";Integrated Security=SSPI;"

        conn = New SqlConnection(strConn)
        Try

            conn.Open()

        Catch SqlEx As SqlException
            MsgBox("Error SQL:" & vbCrLf & vbCrLf & SqlEx.Message, MsgBoxStyle.Critical)

        Catch ex As Exception
            MsgBox("Error message", MsgBoxStyle.Critical)
     
        End Try
        GetConnection = conn
    End Function


    <System.Diagnostics.DebuggerStepThrough()> _
    Public Shared Function ExecuteReader(ByVal query As String) As SqlDataReader
        Dim rdr As SqlDataReader = Nothing
        Dim conn As SqlConnection = GetConnection()

        Try

            Dim cmd As SqlCommand = New SqlCommand(query, conn)

            rdr = cmd.ExecuteReader(CommandBehavior.CloseConnection)

        Catch SqlEx As SqlException
            MsgBox("Error SQL:" & vbCrLf & vbCrLf & SqlEx.Message, MsgBoxStyle.Critical)

        Catch ex As Exception
            MsgBox("Error message", MsgBoxStyle.Critical)

        End Try
        ExecuteReader = rdr
    End Function

Then in the Form:
   Imports System.Data
   Imports System.Data.SqlClient

            Dim SQL As String = "SELECT * FROM YourTable WHERE MyField = " & 123 & " ORDER BY Item;"
            Dim dr As SqlDataReader = ExecuteReader(SQL)
            While dr.Read
                              ' Add itens to listview using  dr.Item("Item")
             End While
             dr = Nothing


Do you know how to insert itens in a listview ?

jpaulino
0
 
john8694Author Commented:
No, I'm sorry I don't.  I will try to insert this code you gave me.  I appreciate the help very much.
0
 
Jorge PaulinoIT Pro/DeveloperCommented:
You have to add the columns in the listview and then you can see in this topic how to add itens. You can check also another example how get data from sql server.

http://www.experts-exchange.com/Programming/Languages/.NET/Visual_Basic.NET/Q_22732225.html

Don't forget that you have to change the SQL statement to include all your variables/filters.

0
 
john8694Author Commented:
Thank you very much.  I have a very good starting point now!
0
 
Jorge PaulinoIT Pro/DeveloperCommented:
Glad I could help. If you need further help just say it.

jpaulino
0

Featured Post

The new generation of project management tools

With monday.com’s project management tool, you can see what everyone on your team is working in a single glance. Its intuitive dashboards are customizable, so you can create systems that work for you.

  • 5
  • 3
Tackle projects and never again get stuck behind a technical roadblock.
Join Now