PC Review


Reply
Thread Tools Rate Thread

Correct syntax for pasing a SELECtT statement in a string

 
 
=?Utf-8?B?R29yZG9u?=
Guest
Posts: n/a
 
      25th Jan 2005

What is the correct syntax for passing a select statement via the Reader.

The following code doesn't return anything.

Dim strSQL2 As String = "SELECT * from ATable WHERE ' " &
ComboBox1.Text & " ' = ' " & TextBox1.Text & " '"

Dim cmd As New OleDbCommand(strSQL2, Conn)
Dim rdr As OleDbDataReader
rdr = cmd.ExecuteReader
ListBox1.Items.Clear()
ListBox1.Items.Add("")
While rdr.Read
ListBox1.Items.Add(rdr("Col_One") & " " & rdr("Col_Two") &
" " & rdr("Col_Three") & " " & rdr("Col_Four"))
End While
rdr.Close()


Thanks
--
Gordon
 
Reply With Quote
 
 
 
 
Ranjan
Guest
Posts: n/a
 
      25th Jan 2005
Column names should not be quoted

Dim strSQL2 As String = "SELECT * from ATable WHERE " &
ComboBox1.Text & " = ' " & TextBox1.Text & " '"

should work.

Ranjan


--
http://dotnetjunkies.com/weblog/dotnut




"Gordon" <(E-Mail Removed)> wrote in message
news2A58BA2-124D-4487-A627-(E-Mail Removed)...
>
> What is the correct syntax for passing a select statement via the Reader.
>
> The following code doesn't return anything.
>
> Dim strSQL2 As String = "SELECT * from ATable WHERE ' " &
> ComboBox1.Text & " ' = ' " & TextBox1.Text & " '"
>
> Dim cmd As New OleDbCommand(strSQL2, Conn)
> Dim rdr As OleDbDataReader
> rdr = cmd.ExecuteReader
> ListBox1.Items.Clear()
> ListBox1.Items.Add("")
> While rdr.Read
> ListBox1.Items.Add(rdr("Col_One") & " " & rdr("Col_Two")

&
> " " & rdr("Col_Three") & " " & rdr("Col_Four"))
> End While
> rdr.Close()
>
>
> Thanks
> --
> Gordon



 
Reply With Quote
 
Cor Ligthert
Guest
Posts: n/a
 
      25th Jan 2005
Gordon,

A webpage sample watch typos changed in this message

\\\
cmd.CommandText = "Select * from tblUsers " & _
"where (UserId = @UserId)"
Dim myparam1 As New OleDb.OleDbParameter("@UserId", _
OleDb.OleDbType.Integer)
cmd.Parameters.Add(myparam1)
myparam1.Value = 1
Dim dr As OleDb.OleDbDataReader
dr = cmd.ExecuteReader()
DataGrid1.DataSource = dr
DataGrid1.DataBind()
///
I hope this helps?

Cor


 
Reply With Quote
 
 
 
Reply

Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Correct syntax for SELECT statement within a SELECT statement. =?Utf-8?B?R3JlZw==?= Microsoft Access ADP SQL Server 2 16th Oct 2006 09:20 PM
What is correct syntax for SQL SELECT statement to read Unicode? =?Utf-8?B?Sm9obiBIYWxs?= Microsoft Dot NET 1 1st May 2005 10:43 PM
select statement into if statement in an event code (syntax error =?Utf-8?B?dG90YQ==?= Microsoft Access VBA Modules 1 12th Dec 2004 11:13 AM
SQL INSERT syntax error, but the statement is correct! kosta Microsoft C# .NET 17 20th Oct 2004 06:29 PM
SQL INSERT syntax error, but the statement is correct! kosta Microsoft C# .NET 7 16th Oct 2004 01:59 PM


Features
 

Advertising
 

Newsgroups
 


All times are GMT +1. The time now is 11:29 PM.