Wrox Programmer Forums
Go Back   Wrox Programmer Forums > Visual Basic > VB.NET 1.0 > Pro VB.NET 2002/2003
|
Pro VB.NET 2002/2003 For advanced Visual Basic coders working .NET version 2002/2003. Beginning-level questions will be redirected to other forums, including Beginning VB.NET.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the Pro VB.NET 2002/2003 section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
 
Old March 27th, 2006, 06:56 PM
Registered User
 
Join Date: Feb 2006
Posts: 2
Thanks: 0
Thanked 0 Times in 0 Posts
Default How to give the value to a where - between

Hi There,
I have a onclick event on my vb.net form.
I have two text box, OTBOX AND OTEND.
I want the users to enter two order #s one one each of the two text box. I want to use these order #s as input to my querry which has a WHERE clause with has a between criteria.
I have hard coded two WO# FOR THE BETWEEN CONDITION TO CHECK. IT was fine, but I want to be able to use the input from the text box.

System.Data.OleDb.OleDbDataAdapter("Select [WO #], [Dash #], Req AS [Order DT], Approved, Code, [Item#], Cus,ID from Approve where [WO #] between 136300 and 136400 ORDER by [WO #] ", myConnection)

I WANT TO BE ABLE TO USE THE USERS INPUT ON OTBOX.TEXT AND OTEND.TEXT
IN PLACE OF 136300 AND 136400.
I would appreciate if anybody can tell me how I can do that.
Please find below the entire onclick event.


Please find my code below

Private Sub ORDBTN_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles ORDBTN.Click
        'lboResults.Items.Clear()

        Try
        
        ' create a connection string
        Dim connString As String = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=D:\ USE.mdb"
        Dim myConnection As System.Data.OleDb.OleDbConnection = New System.Data.OleDb.OleDbConnection
        myConnection.ConnectionString = connString
            ' create a data adapter

            Dim da As System.Data.OleDb.OleDbDataAdapter = New System.Data.OleDb.OleDbDataAdapter("Select [WO #], [Dash #], Req AS [Order DT], Approved, Code, [Item#], Cus,ID from Approve where [WO #] between 136300 and 136400 ORDER by [WO #] ", myConnection)

I tried this doesn't work

            ' da.SelectCommand.Parameters("[WO #]").Value() = OTBOX.Text ' create a new dataset
        Dim ds As DataSet = New DataSet
        ' fill dataset
            da.Fill(ds, "Approve")
    
            Me.DataGrid1.DataSource = ds.Tables("Approve").DefaultView

        Catch ex As Exception
            MsgBox(ex.Message + vbCrLf + ex.Source & vbCrLf & vbCrLf & ex.StackTrace, MsgBoxStyle.Critical, "Error")
        End Try
    End Sub
 
Old May 5th, 2006, 11:55 AM
Friend of Wrox
 
Join Date: Nov 2004
Posts: 1,621
Thanks: 1
Thanked 3 Times in 3 Posts
Default

Code:
Imports System.Data.OleDb

Private Sub ORDBTN_Click(ByVal sender As System.Object, _
                         ByVal e As System.EventArgs) Handles ORDBTN.Click

    Try       
        ' Create a connection string 
        Dim connString As String = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=D:\ USE.mdb"
        Dim myConnection As OleDbConnection = _
                        New OleDbConnection
        myConnection.ConnectionString = connString
        ' Create a data adapter 

        Dim da As OleDbDataAdapter = _
              New OleDbDataAdapter("SELECT  [WO #], [Dash #], Req AS [Order DT], " & _
                                   "        Approved, Code, [Item#], Cus,ID " & _
                                   "FROM Approve " & _
                                   "WHERE [WO #] BETWEEN " & OTBOX.TEXT & " AND " & OTEND.TEXT  " " & _
                                   "ORDER BY [WO #] ", _
                                   myConnection)
        ' I am presuming that [WO #] is not text.  If it is, use:
        ' . . .BETWEEN '" & OTBOX.TEXT & "' AND "' & OTEND.TEXT  "' . . . "
        '              ^                  ^      ^                ^

        Dim ds As DataSet = New DataSet

        ' Fill dataset 
        da.Fill(ds, "Approve")

        Me.DataGrid1.DataSource = ds.Tables("Approve").DefaultView

    Catch ex As Exception
        ' When concatenating strings, use “&,” not “+.”  If any of the pieces
        ' are Null, the whole concatenation will be Null if “+” is used, but
        ' the Null will be treated as an empty string by “&.”
        MsgBox(ex.Message + vbCrLf + ex.Source & vbCrLf & vbCrLf & ex.StackTrace, _
               MsgBoxStyle.Critical, _
               "Error")
    End Try

End Sub





Similar Threads
Thread Thread Starter Forum Replies Last Post
Please give me solution deepak.deemca C++ Programming 1 October 17th, 2007 04:27 PM
please give me a help wujilin SQL Server 2005 2 June 2nd, 2007 04:33 PM
please give me a help wujilin SQL Language 2 May 28th, 2007 07:52 AM
give me solution asudhakar ASP.NET 1.0 and 1.1 Basics 2 March 19th, 2007 09:33 AM
Help!Give me some advices! yuyijq General .NET 2 March 17th, 2005 08:06 AM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.