Wrox Programmer Forums
Go Back   Wrox Programmer Forums > Database > SQL Language
|
SQL Language SQL Language discussions not specific to a particular RDBMS program or vendor.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the SQL Language 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 December 21st, 2006, 02:46 PM
Authorized User
 
Join Date: Dec 2006
Posts: 43
Thanks: 4
Thanked 0 Times in 0 Posts
Send a message via MSN to Yasho
Default Select statement with where clause for visual basi

I am using Microsoft Visual Basic .NET.
   I am trying to match the numeric Value of Column "Number" from user input. The column number is Primary Key, auto Generated, type Single.
When I debug I get this error code
Error"An unhandled exception of type 'System.Data.OleDb.OleDbException' occurred in system.data.dll"

Problem is the construction of Select Statement. I know my syntex is wrong but dont know the correct syntex. I do not have any problem when I use a sting to match a string vlaue. Every resource I consulted only has syntex for string Value
"What is the correct syntex for a numeric Value ?"

my code
  Dim SearchEquip As Single
  Dim SearchString As String

        SearchEquip = CSng(txtEquipID.Text)
        SearchString = "Select * from TblInven
        where Number ='txtEquipID.Text';"
        Dstest1.Clear()
        daTest.SelectCommand.CommandText = SearchString
        daTest.Fill(Dstest1)
        With Dstest1
            lst1.Items.Add(.tblInven(0).Title)
        End With
Dat




yvk
__________________
yvk
 
Old December 21st, 2006, 02:49 PM
Friend of Wrox
 
Join Date: Jun 2003
Posts: 2,189
Thanks: 5
Thanked 59 Times in 57 Posts
Send a message via MSN to gbianchi
Default

hi there...

SearchString = "Select * from TblInven where Number = "& txtEquipID.Text

do exactly like you do with textboxes... ;)




HTH

Gonzalo
 
Old December 21st, 2006, 02:58 PM
Authorized User
 
Join Date: Dec 2006
Posts: 43
Thanks: 4
Thanked 0 Times in 0 Posts
Send a message via MSN to Yasho
Default

Special Thanks to Mr. Bianchi.
Yasho

yvk
 
Old January 1st, 2007, 01:39 PM
Authorized User
 
Join Date: Jan 2007
Posts: 46
Thanks: 2
Thanked 1 Time in 1 Post
Default

You do need to use the val('string') to convert the value entered into the textbox to numeric one.

 
Old January 11th, 2007, 06:14 AM
Registered User
 
Join Date: Jan 2007
Posts: 1
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Dear Yasho....

Maybe you can try my code :)

Imports System.Data
Imports System.Data.SqlClient
Public Class Form1
  Dim ds As DataSet
  Dim da As SqlDataAdapter
  Dim scnn As SqlConnection
  Dim cm As SqlCommand


  Private Sub Form1_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
    scnn = New SqlConnection("Data Source=server;Initial Catalog=Northwind;User ID=d;Password=d")
    cm = New SqlCommand("Select * From Orders Where EmployeeID = '" & CInt(TextBox1.Text) & "'", scnn)
    da = New SqlDataAdapter(cm)
    ds = New DataSet("Orders")
    da.Fill(ds)
    Me.DataGrid1.DataSource = ds

  End Sub
End Class

ARIES

admin23383
 
Old May 15th, 2007, 11:40 PM
Authorized User
 
Join Date: Dec 2006
Posts: 43
Thanks: 4
Thanked 0 Times in 0 Posts
Send a message via MSN to Yasho
Default

I appreciate for all the suggestions and help i got. They all work.
 But what if the querry is not in string format say if the statement is as under.

Suppose we substitute date with a field which is a number then what will be the formate.

Dim mySearchString As String

 mySearchString = "Select LastName,MI, Address,State, ZipCode, Phone from tblCustomerInfo where FirstName=' " & txtFirstName.Text " ' "&" And Sdate beteween formateDateTime(txtstartdate.text) and formateDateTime(txtenddate.text)
            DsCust1.Clear()
            daCust.SelectCommand.CommandText = mySearchString

                dgrCustomers.Refresh()
                daCust.Fill(DsCust1)

    End Sub

I will also like you learned people to guide me to a good book which covers these sql command requirements



yvk
 
Old May 16th, 2007, 01:00 AM
Friend of Wrox
 
Join Date: Jun 2003
Posts: 2,480
Thanks: 0
Thanked 1 Time in 1 Post
Default

Quote:
quote:Suppose we substitute date with a field which is a number then what will be the formate.
Assuming the date value that you pass is going to be in the right format you can always compare it the way you do for comparing a number.

_________________________
- Vijay G
Strive for Perfection





Similar Threads
Thread Thread Starter Forum Replies Last Post
Case Statement In Where Clause Logic dwj119 SQL Server 2000 4 October 27th, 2011 03:14 PM
If statement in WHERE clause frakey Classic ASP Basics 30 July 8th, 2008 03:35 PM
Select statement with where clause with 2 conditon Yasho VB.NET 2002/2003 Basics 7 May 16th, 2007 01:40 PM
If statement in Where Clause jdziggy SQL Server 2000 2 March 16th, 2007 08:08 AM
USING SQL IF Statement in WHERE clause rit01 SQL Server 2000 17 March 15th, 2007 08:33 AM





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