Wrox Programmer Forums
Go Back   Wrox Programmer Forums > .NET > .NET 1.0 and Visual Studio.NET > VS.NET 2002/2003
| Search | Today's Posts | Mark Forums Read
VS.NET 2002/2003 Discussions about the Visual Studio.NET programming environment, the 2002 (1.0) and 2003 (1.1). ** Please don't post code questions here ** For issues specific to a particular language in .NET, please see the other forum categories.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the VS.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 April 8th, 2006, 10:05 PM
Authorized User
 
Join Date: Jan 2006
Location: , , .
Posts: 23
Thanks: 0
Thanked 0 Times in 0 Posts
Default In Code Behind, What is proper select statement sy

In Code Behind, What is proper select statement syntax to retrieve the @BName field from a table?
Using Visual Studio 2003
SQL Server DB

I created the following parameter:
Dim strName As String
        Dim parameterBName As SqlParameter = New SqlParameter("@BName", SqlDbType.VarChar, 50)
        parameterBName.Value = strName
        myCommand.Parameters.Add(parameterBName)

I tried the following but get error:
Dim strSql As String = "select @BName from Borrower where BName= DOROTHY V FOWLER "

error is:
Line 1: Incorrect syntax near 'V'.
Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code.

Exception Details: System.Data.SqlClient.SqlException: Line 1: Incorrect syntax near 'V'.

Source Error:


Line 59:
Line 60:
Line 61: myCommand.ExecuteNonQuery() 'Execute the query
 
Old April 8th, 2006, 10:47 PM
Authorized User
 
Join Date: Jan 2006
Location: , , .
Posts: 23
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Sorry: To further clarify
My database table name is borrower and two of the fields are BName and TaxID, I am trying to select a particular borrower (BName) with a taxid OF 767, lets say in this case THE BORROWER IS Bill Jones

I declared the following variables:
Dim strName As String
        Dim parameterBName As SqlParameter = New SqlParameter("@BName", SqlDbType.VarChar, 50)
        parameterBName.Value = strName
        myCommand.Parameters.Add(parameterBName)
        Dim strTaxID As String
        Dim ParameterTaxID As SqlParameter = New SqlParameter("@TaxID", SqlDbType.VarChar, 15)
        ParameterTaxID.Value = strTaxID
        myCommand.Parameters.Add(ParameterTaxID)

 I inserted the folowing command:

Dim strSql As String = "select BName from Borrower where TaxID= @333-00-1492 "

I get error:
Must declare the variable '@333'.





 
Old April 9th, 2006, 04:14 AM
Imar's Avatar
Wrox Author
Points: 70,322, Level: 100
Points: 70,322, Level: 100 Points: 70,322, Level: 100 Points: 70,322, Level: 100
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Jun 2003
Location: Utrecht, Netherlands.
Posts: 17,089
Thanks: 80
Thanked 1,576 Times in 1,552 Posts
Default

I am not sure I understand what you're trying to do...

You have a variable called strName, but never assign it a value. And where does 333-00-1492 come from? I thought you needed 767?

Anyway, if I were you, I'd try a simple query first. E.g.

"select BName from Borrower where TaxID = 767"

assuming the TaxId is a number or

"select BName from Borrower where TaxID = '767'"

If that works, then you can modify the statement to insert a parameter:

"select BName from Borrower where TaxID = @taxId"

Then you can set up a parameter for the @taxId param.

Hope this helps,

Imar
---------------------------------------
Imar Spaanjaars
Everyone is unique, except for me.
Author of ASP.NET 2.0 Instant Results and Beginning Dreamweaver MX / MX 2004




Similar Threads
Thread Thread Starter Forum Replies Last Post
Select from another select statement to a repeater simsen ASP.NET 2.0 Professional 0 May 2nd, 2007 04:34 PM
Code conversion and proper attribution qnr BOOK Beginning Linux Programming, 3rd Edition 1 April 5th, 2006 12:48 AM
Select Statement jmss66 VB How-To 3 March 13th, 2006 03:55 PM
Select Into statement ashu_from_india Oracle 8 October 9th, 2005 11:30 PM
Select statement dungey PHP Databases 4 December 14th, 2004 04:08 PM





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