| Skype: | TextControlSupport | |
| Orders: | 877-462-4772 |

| Author: | TX Text Control Support Department |
| Language: | Visual Basic .NET |
| Version: | 1.0 |
| Released: | August 04, 2004 |
| Last modified: | January 11, 2008 |
| Requirements: | TX Text Control .NET with Visual Basic .NET |
| Download code: | database.zip |
Using TX Text Control ActiveX and Visual Basic 6, you can use an ADO Data Control (ADODC) to select records from a database or create a database connection at run-time. In Visual Basic .NET, you can do exactly the same; however there are a few differences in the implementation.
This sample shows you how to work with an Access database using TX Text Control .NET.
We use the OLE database connection to open an Access database. First of all, we need to create a connection string that contains the path of the database and the database interface that is being used. Using this string, we create a new OLE database connection.
strPath = CurDir(Application.ExecutablePath) & "\rtf_default.mdb" strCon = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" & strPath oleCon = New System.Data.OleDb.OleDbConnection(strCon)
After declaring the connection and setting the Connection string, we can open the database.
oleCon.Open() oleAdp = New System.Data.OleDb.OleDbDataAdapter("select * from Table1", oleCon) oleAdp.Fill(dsF, "Table1") oleCon.Close()
The SQL statement SELECT fills a DataSet with the rows of Table1. To get the values of a specific field in a row we create a DataRow and fill it with the specific data.
Dim rw As DataRow = dsF.Tables("Table1").Rows(iRw)
One database field in a row can be accessed by specifying the columns name.
Dim btBuffer As String = rw("document")
In our sample, we have a database storing RTF documents. These documents are going to be loaded into a variable and imported into TX Text Control .NET using the Load method.
TextControl1.Load(btBuffer, TXTextControl.StringStreamType.RichTextFormat)
To insert a document into the database, we have to save the contents to a variable and insert them into the database using the INSERT SQL statement. In this sample, we step forward and backwards through the database and insert new documents into the database in RTF format.
TextControl1.Save(txContent, TXTextControl.StringStreamType.RichTextFormat) Dim sqlStr As String = "Insert Into Table1(document) VALUES('" & txContent & "')"
In order that this example applications will run, you have to have TX Text Control .NET (trial or full) and Visual Studio .NET 2003 installed on your PC.