tag:blogger.com,1999:blog-22880204871103428732024-03-06T09:18:22.798+07:00Just another Visual Basic weblogUnknownnoreply@blogger.comBlogger10125tag:blogger.com,1999:blog-2288020487110342873.post-69768278721831851792010-09-12T14:39:00.000+07:002010-09-12T14:39:11.471+07:00Database, Reading an XML File into In-Memory Data TablesProblemYou previously exported a DataSet to an XML file, and now you need to get it back.
SolutionUse the DataSet object's ReadXML() method to restore data from a previously generated XML export.
DiscussionRecipe 13.9 exports some XML and a related schema for a table with state-specific information. To read it back into a DataSet object, use the following code:Dim stateSet As New Unknownnoreply@blogger.com0tag:blogger.com,1999:blog-2288020487110342873.post-85562060404776982672010-09-12T14:32:00.000+07:002010-09-12T14:32:41.406+07:00Database, Writing In-Memory Data Tables to an XML FileProblemYou have some data in a DataSet object, and you would like to export it to an XML file for later reimportation.
SolutionUse the DataSet's WriteXML() method to send the DataSet content to the file in a common XML format.
DiscussionRecipe 13.8 builds a DataTable object with two state-specific records. The following code adds that table to a DataSet object and writes its records to an Unknownnoreply@blogger.com0tag:blogger.com,1999:blog-2288020487110342873.post-65136097905109975992010-09-12T14:25:00.001+07:002010-09-12T14:31:28.283+07:00Database, Creating In-Memory Data Tables ManuallyProblemYou want to manage some data in a database-table-like fashion, but the source data is not coming from a database, or from anything that looks like a table.
SolutionBuild a DataTable manually, and fill in all the table details and data yourself.
DiscussionThe following code builds a simple table of state information and adds two records:Dim stateTable As DataTable = New DataTable("Unknownnoreply@blogger.com0tag:blogger.com,1999:blog-2288020487110342873.post-39313628598034647142010-09-12T14:09:00.000+07:002010-09-12T14:09:42.142+07:00Database, Storing the Results of a Query in MemoryProblemWhile a data reader is fast and convenient, you would like to keep the retrieved data around for a while, even when you are disconnected from the database or other data source.
SolutionUse the data reader to bring the results into a data set. The DataSet object represents one or more in-memory database tables, each with its records stored in a separate DataTable object.
DiscussionTheUnknownnoreply@blogger.com0tag:blogger.com,1999:blog-2288020487110342873.post-82913006716323032632010-09-12T13:37:00.000+07:002010-09-12T13:37:53.702+07:00Database, Using TransactionProblemYou need to issue multiple database updates in the context of a single, atomic transaction.
SolutionUse an ADO.NET transaction to envelop the various SQL statements that need to be processed as a unit.
DiscussionThe following block of code connects to a database via ADO.NET and makes several database updates within a single transaction:' ----- Connect to the database.
Dim Unknownnoreply@blogger.com0tag:blogger.com,1999:blog-2288020487110342873.post-31300768327675969232010-09-12T13:25:00.001+07:002010-09-12T13:28:50.694+07:00Database, Using Stored Procedures
ProblemYou need to use a stored procedure in your database, and you're not sure how to specify values for its input and output parameters.
SolutionUse the command object's Parameters collection to set and retrieve stored procedure argument values.
DiscussionHere's a simple SQL Server stored procedure that does nothing more than retrieve a field from a table given its ID value:CREATE Unknownnoreply@blogger.com0tag:blogger.com,1999:blog-2288020487110342873.post-24362036585234183962010-09-06T15:21:00.004+07:002010-09-06T15:37:13.214+07:00Format the DataGridViewFormatting the .NET 1.x DataGrid ranges from awkward to nearly impossible. However, thanks to its multi-layered model, formatting the DataGridView is far easier. This model builds on a single class, the DataGridViewCellStyle, which encapsulates key formatting properties. You can assign different DataGridViewCellStyle objects to separate rows, columns, or even distinct cells.
Note: By usingUnknownnoreply@blogger.com0tag:blogger.com,1999:blog-2288020487110342873.post-52018215547324946712008-09-11T14:06:00.004+07:002010-09-07T09:39:19.973+07:00Issuing SQL CommandsProblem
Now that you've established a connection to a database through a provider, you're ready to issue SQL commands. But how?
Solution
Use a Command object to issue SQL commands directly to your database through the provider connection.
Discussion
The following code updates a SQL Server table named Table1, changing every Column2 field to 25 whenever Column1 has a value of 0:
' ----- Connect Unknownnoreply@blogger.com0tag:blogger.com,1999:blog-2288020487110342873.post-62702420946190934962008-09-11T13:57:00.006+07:002010-09-07T09:41:50.259+07:00Connecting to a Data ProviderProblem
You are writing an application that interacts with a database, and you need to connect to it to run some queries.
Solution
Use a Connection object and a "connection string" to establish the connection you will use for queries and updates.
Discussion
The following set of statements establishes a connection to a SQL Server Express database named MyDatabase running on the system named Unknownnoreply@blogger.com0tag:blogger.com,1999:blog-2288020487110342873.post-34740247290154533742008-09-04T13:05:00.004+07:002010-09-06T14:55:27.366+07:00andLinux, run Linux applications in WindowsFor those who like to run Linux applications but still use a PC that had Windows OS, now do not need to go back and forth reboot to run a dual boot or run a virtualization program such a Virtual PC or Virtual Box. With andLinux now we can run linux applications in windows as if the applications are Windows applications.andLinux uses the Ubuntu Linux distribution that runs in a seamless Unknownnoreply@blogger.com1