Wrox Programmer Forums
| Search | Today's Posts | Mark Forums Read
BOOK: Visual Basic 2008 Programmer's Reference ISBN: 978-0-470-18262-8
This is the forum to discuss the Wrox book Visual Basic 2008 Programmer's Reference by Rod Stephens; ISBN: 9780470182628
Welcome to the p2p.wrox.com Forums.

You are currently viewing the BOOK: Visual Basic 2008 Programmer's Reference ISBN: 978-0-470-18262-8 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
  #1 (permalink)  
Old July 3rd, 2009, 06:20 PM
Authorized User
Points: 312, Level: 6
Points: 312, Level: 6 Points: 312, Level: 6 Points: 312, Level: 6
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Jun 2006
Location: Orpington, Kent, United Kingdom.
Posts: 73
Thanks: 1
Thanked 1 Time in 1 Post
Question Adapting Ch. 20 code, to create a 'SELECT' DataSet ?

I'm using the following code to crete a new dataset, which then repopulates a DataGridView, based on an 'Add Query' DataSet ( creted using the wizard ). I'd like to know the underlying code, so I can slightly adapt it in a sub-routine. For example

Private Sub btnWhatever_Click( ..................................... and so on )

create connection to DB
create an SQL command with (?) in appropriate WHERE clause.
pass the parameter(s) to the command.
execute the command.
fill the DataGridView with new DataSet
close connection

End Sub()

Code:

PrivateSub btnABig_Click(ByVal sender AsObject, ByVal e As System.EventArgs)_ & Handles btnABig.Click
 
Try
Me.CustomersTableAdapter.initA(Me.Bm2009Customers.Customers)
Catch ex As System.Exception
System.Windows.Forms.MessageBox.Show(ex.Message)
EndTry
EndSub

In Ch. 20 there's only examples for non-query routines. Any help much appreciated.
  #2 (permalink)  
Old July 7th, 2009, 10:56 AM
Registered User
 
Join Date: Jun 2009
Posts: 7
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Hi ,

If you are using Wizard to create a DataSet and Tables Adapter use the following code to fill the corresponding tables.
Code:
DataSet1 ds1 = new DataSet1();
AnyTableAdapter ata = new AnyTableAdapter();
ata.Fill(ds1.anyTable);
In any other case if u try to fill programmatic ally use the following methods fill by procedure and fill by Query.

Return DataTable fill by Query method
Code:
 public DataTable RunSelectQuery(string sqlQuery, OracleParameter[] @params)
        {
            OracleDataAdapter objDataAdapter = default(OracleDataAdapter); ;
            DataTable dt = new DataTable();
            try
            {
                OpenConnection();
                OracleCommand cmd = new OracleCommand(sqlQuery, dbConnection);
                cmd.CommandType = CommandType.Text;
                objDataAdapter = new OracleDataAdapter(cmd);               
                ResolveParameters(ref cmd, @params);
                objDataAdapter.Fill(dt);
            }
            catch (Exception oErr)
            {               
                throw oErr;
            }
            finally
            {
                CloseConnection();
                if ((objDataAdapter != null)) objDataAdapter.Dispose();
            }
            return dt;
        }
Return DataSet fill By procedure
Code:
 public DataSet FillDataSetWithProcedure(string spName, OracleParameter[] @params)
        {
            DataSet returnDs = new DataSet();
            OracleDataAdapter da = new OracleDataAdapter();
            OracleCommand cmd = new OracleCommand();
            try
            {
                OpenConnection();
                cmd = new OracleCommand(spName, dbConnection);
                cmd.CommandType = CommandType.StoredProcedure;             
                ResolveProcParameters(ref cmd, @params);
                da = new OracleDataAdapter(cmd);
                da.Fill(returnDs);
            }
            catch (Exception ex)
            {               
                throw ex;
            }
            finally
            {
                CloseConnection();
                if ((da != null)) da.Dispose();
                if ((cmd != null)) cmd.Dispose();
            }

            return returnDs;
        }
The return data Source assigned to specified DataGridView to fill the record.

The above code return in C# supported by Oracle Data Access . if you need any further help let me know about it.


Similar Threads
Thread Thread Starter Forum Replies Last Post
Try it out:Ch 16 Dataset Example flhartley VB.NET 2002/2003 Basics 1 August 28th, 2009 07:00 AM
SQL Express & Ch 20 Nick Y BOOK: Ivor Horton's Beginning Visual C++ 2005 1 August 2nd, 2007 05:16 PM
TCPSend/ Receive system.dll problem (ch 20) dingke BOOK: Professional C#, 2nd and 3rd Editions 0 March 10th, 2004 05:42 PM





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