Visual Basic .Net to Synchronize data from Remote Database Server

0 comments

Posted on 6th December 2011 by Kenneth in Visual Basic .Net

, ,

VB.NetOccasionally Connected Data (OCS) to synchronize data from remote database server. This downloads data from the server to the .sdf file. Next, make data changes in the server data grid, and then click the save button.ClickSynchronizeagain to download your changes to the client. Get full source code here


How to Connect Database in Visual Basic .Net

0 comments

Posted on 3rd December 2011 by Admin in Visual Basic .Net

,

Sample project on Visual Basic .Net in windows forms on how connect to an existing database and how to define how data is retrieved and updated using the data sources window and the dataset designer in Visual Studio. Download Project


Visual Basic .Net – Binding to Windows Forms Controls

1 comment

Posted on 7th June 2010 by Admin in Visual Basic .Net

,

The .NET Framework brings a wide variety of controls to the developer. The Windows Forms controls are found in the System.Windows.Forms namespace, and the vast majority of them support data binding. In general, data binding to a control is far from challenging. It requires that you use an in-memory data store and can usually accept either a DataTable or a DataSet.

The mechanism is very simple. Take a look at the following example, using a DataTable:

Dim adapter As New OleDbDataAdapter("Select * From Customers", _ connStr)
Dim dt As New DataTable()

' Import the query results into the DataTable
adapter.Fill(dt)

' Bind the DataTable to the DataGrid
DataGrid1.DataSource = dt

The DataSet works in almost exactly the same way:

Dim adapter As New OleDbDataAdapter("Select * From Customers", connStr)
Dim ds As New DataSet()

' Import the query results into the DataSet
adapter.Fill(ds)

' Bind a DataTable from the DataSet to the DataGrid
DataGrid1.DataSource = ds.Tables("Customers")

Notice in this example that instead of passing the entire DataSet to the DataGrid, weve chosen to bind only a single table. This is often necessary with controls for which multiple sets of tables dont make sense. The DataGrid is not one of these controls, however. It is capable of a multitable display (try it) and likes the DataSet just fine.

How to use DataView in Visual Basic .Net

0 comments

Posted on 7th June 2010 by reyman in Visual Basic .Net

, ,

A DataView is an object that allows you to create multiple views of your data and that can be used for data binding. The concept is fairly simple, but its importance cannot be overstated. The flexibility it introduces is impressive because a DataView does not actually change the DataTable from which it is generated. Instead, it offers a filtered window to the data. The following code shows how you can use the DataView control to filter rows based on a column value (in this case, the FirstName and LastName columns):

Function TestDataView()
   Dim adapter As New OleDbDataAdapter("Select * From Customers", _
   connStr)
   Dim ds As New DataSet()

   adapter.Fill(ds)

   Dim view1 As DataView = ds.Tables("Customers").DefaultView
   Dim view2 As DataView = ds.Tables("Customers").DefaultView

   view1.RowFilter = "'LastName' Like 'O%'"
   view2.RowFilter = "'FirstName' Like 'E%'"

   Dim i As Integer

   Debug.WriteLine("All LastNames starting with 'O'")
   For i = 0 To view1.Count - 1
      Debug.WriteLine(view1(i)("LastName"))
   Next

   Debug.WriteLine("All FirstNames starting with 'E'")
   For i = 0 To view2.Count - 1
      Debug.WriteLine(view1(i)("FirstName"))
   Next
End Function

Read and Write Text File in Visual Basic .Net

0 comments

Posted on 7th June 2010 by Kenneth in Visual Basic .Net

,

While were on the subject of the new file functions, lets take a short digression and quickly discuss how to write to and read from files using the new .NET Framework methods. You can still use the existing Visual Basic file functions, but the .NET Framework file methods, although a little more complicated, offer more flexibility when working with files.

Well create a simple console application that creates a file, writes Hello World to it, closes the file, and then reopens it and shows the contents in a message box.

Sub Main()
   '* Create a file and write to it
   Dim outFile As System.IO.FileStream
   outFile = New System.IO.FileStream("C:tempFile.txt", _
      IO.FileMode.Create, IO.FileAccess.Write)
   Dim fileWriter As New System.IO.StreamWriter(outFile)
   fileWriter.WriteLine("Hello World")
   fileWriter.Close()
   outFile.Close()

   '* Open a file and read from it
   Dim inFile As System.IO.FileStream
   inFile = New System.IO.FileStream("C:tempFile.txt", _
      IO.FileMode.Open, IO.FileAccess.Read)
   Dim fileReader As New System.IO.StreamReader(inFile)
   While fileReader.Peek > -1
      MsgBox(fileReader.ReadLine)
   End While
   fileReader.Close()
   inFile.Close()
 End Sub

To open a file for writing, you have to perform two steps: create a stream object and then create a StreamWriter object to write to the stream. You can then write to the file using the StreamWriter objects Write and WriteLine methods. Reading from a file involves a similar process: create a stream object, and then create a StreamReader to read from the stream. To determine whether there is anything to read from the file, use the StreamReader objects Peek method, which returns the value of the next byte in the file, or 1 if there is nothing left to read. The StreamReader objects Read, ReadBlock, ReadLine, and ReadToEnd methods are used to read the contents of the file.