Wrox Programmer Forums
|
VB.NET 2002/2003 Basics For coders who are new to Visual Basic, working in .NET versions 2002 or 2003 (1.0 and 1.1).
Welcome to the p2p.wrox.com Forums.

You are currently viewing the VB.NET 2002/2003 Basics 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 9th, 2003, 04:51 AM
Friend of Wrox
 
Join Date: Sep 2003
Posts: 130
Thanks: 0
Thanked 0 Times in 0 Posts
Default Varing Where Clause

Hi

I have just started to learn VB.Net, I would like to create a recoredset where I pass different varaibles into the where clause, I do have an example, but it is for SQL, where as I am using a Access back end.

for example:-
select *
from Table
Where ?
entered into the dataadapter and

sqldataadapter1.selectcommand.parameters("@Param1" ).value = "Clause"

in the code

I have tried replacing the SQL dataaapter with a OLE one, but it didn't work.

Very stuck

Thanks

Louisa


 
Old December 9th, 2003, 02:34 PM
Friend of Wrox
 
Join Date: Jun 2003
Posts: 540
Thanks: 0
Thanked 4 Times in 4 Posts
Default

Try this:

Make sure you import your namespaces at the top of the page:

Imports System.Data
Imports System.Data.OLEDB

---------------------------

For this example, this could go in a button's click event:

---------------------------

Dim conn as OleDbConnection
Dim da as OleDBAdapter
Dim ds as New DataSet

conn = New OleDbConnection("Provider=Microsoft.Jet.OLEDB.4.0; Data Source=drivename:\Path\DBName.mdb")

da = New OleDBDataAdapter("SELECT * FROM Table WHERE pri_key = " & txtInput.Text, conn)

da.Fill(ds, "NameYourDSTable")

---------------------------

You can then fill a datagrid (or something else) by:

dgName.DataSource = ds.Tables("NameYourDSTable").DefaultView

dgName.DataBind()

---------------------------

Note that for this example, you will have to have a datagrid on your form named "dgName". You will also have to have a text box named "txtInput" and a button or something to respond to the change in the text box.

I think I got everything. Hope this helps.

J
 
Old December 10th, 2003, 06:29 AM
Friend of Wrox
 
Join Date: Sep 2003
Posts: 130
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Very helpful

Thank you very much

Louisa






Similar Threads
Thread Thread Starter Forum Replies Last Post
date between clause mateenmohd Access 2 January 7th, 2008 09:28 AM
SQL Where Clause sudarshan73 Crystal Reports 2 January 11th, 2006 10:01 AM
Order by clause mateenmohd SQL Server 2000 4 April 6th, 2004 06:48 AM
More than 1 WHERE clause? onlyu2 MySQL 1 March 26th, 2004 01:48 PM
HAVING clause Adam H-W SQL Server ASP 2 February 11th, 2004 01:37 PM





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