|
|
 |
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 p2p Programmer to Programmer discussion community. This is a community of more than 40,000 computer programmers including Wrox book authors and readers. As a guest, you can read any forum posting. By joining our free Wrox p2p community you can post your own programming questions and respond to other programmers’ questions. Registered users also don't have to see the ads that are displayed to guests. Registration is fast, simple and absolutely free so please, join today!
Join today and post to win prizes! Post more to increase your chances of being Wrox’s top poster of the month.
|
 |

July 3rd, 2009, 07:20 PM
|
|
Authorized User
|
|
Join Date: Jun 2006
Location: Orpington, Kent, United Kingdom.
Posts: 46
Thanks: 0
Thanked 1 Time in 1 Post
|
|
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.
|

July 7th, 2009, 11:56 AM
|
|
Registered User
|
|
Join Date: Jun 2009
Posts: 7
Thanks: 0
Thanked 0 Times in 0 Posts
|
|
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.
|
| Thread Tools |
Search this Thread |
|
|
|
| Display Modes |
Linear Mode
|
Posting Rules
|
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts
HTML code is Off
|
|
|
|
 |