Windows Develop Bookmark and Share   
 index > Windows Forms Data Controls and Databinding > Inport RTF to Access
 

Inport RTF to Access

I need import RTF files into Access with TEXT format, not OLE format.
But I don't know how to make it.
Does anyone can help me?
Thanks in advance.
Schweic  Thursday, September 03, 2009 8:37 AM
Hi Schweic,

We can create a OleDb connection to update data to Access. The oledb type of the text type in Access is OleDbType.VarWChar. This is a code sample:
private string CONNECTION_STRING = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=C:\mydatabase.mdb;User Id=admin;Password=;";
private void WriteToAccess()
{
    OleDbConnection myConnection = null;
    try
    {
        //Get the rtf text.
        string rtf = GetRtf();
        string title = "rtf1";

        //create the SQL statement to add the rtf data
        myConnection = new OleDbConnection(CONNECTION_STRING);
        OleDbCommand myCommand = new OleDbCommand("INSERT INTO rtf_table (rtf_title, rtf_content) VALUES ('" + title + "', ?)", myConnection);
        OleDbParameter myParameter = new OleDbParameter("@rtf",OleDbType.VarWChar);
        myParameter.Value = rtf;
        myCommand.Parameters.Add(myParameter);

        //open the connection and execture the statement
        myConnection.Open();
        myCommand.ExecuteNonQuery();
    }
    finally
    {
        myConnection.Close();
    }
}


These are some related links:
OleDbType Enumeration vs. Microsoft Access Data Types: http://support.microsoft.com/kb/320435.
OleDb namespace: http://msdn.microsoft.com/en-us/library/system.data.oledb(VS.71).aspx
OleDb instruction: http://msdn.microsoft.com/en-us/library/ms722784(VS.85).aspx.

Regards,
Aland Li
Please mark the replies as answers if they help and unmark if they don't. This can be beneficial to other community members reading the thread.
Aland Li  Friday, September 04, 2009 12:44 PM
Hi Schweic,

We can create a OleDb connection to update data to Access. The oledb type of the text type in Access is OleDbType.VarWChar. This is a code sample:
private string CONNECTION_STRING = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=C:\mydatabase.mdb;User Id=admin;Password=;";
private void WriteToAccess()
{
    OleDbConnection myConnection = null;
    try
    {
        //Get the rtf text.
        string rtf = GetRtf();
        string title = "rtf1";

        //create the SQL statement to add the rtf data
        myConnection = new OleDbConnection(CONNECTION_STRING);
        OleDbCommand myCommand = new OleDbCommand("INSERT INTO rtf_table (rtf_title, rtf_content) VALUES ('" + title + "', ?)", myConnection);
        OleDbParameter myParameter = new OleDbParameter("@rtf",OleDbType.VarWChar);
        myParameter.Value = rtf;
        myCommand.Parameters.Add(myParameter);

        //open the connection and execture the statement
        myConnection.Open();
        myCommand.ExecuteNonQuery();
    }
    finally
    {
        myConnection.Close();
    }
}


These are some related links:
OleDbType Enumeration vs. Microsoft Access Data Types: http://support.microsoft.com/kb/320435.
OleDb namespace: http://msdn.microsoft.com/en-us/library/system.data.oledb(VS.71).aspx
OleDb instruction: http://msdn.microsoft.com/en-us/library/ms722784(VS.85).aspx.

Regards,
Aland Li
Please mark the replies as answers if they help and unmark if they don't. This can be beneficial to other community members reading the thread.
Aland Li  Friday, September 04, 2009 12:44 PM

You can use google to search for other answers

Custom Search

More Threads

• AutoComplete Using Simple DropDownStyle ComboBox (Windows Forms 2.0)
• DataGridView - how to prevent deselect in full-row single-select mode ?
• DetailsViews and Custom Classes
• Combo Box Tabbing issue
• Disable update of the datagridview
• DataGridView Problems Adding New Row
• ScrollBars in DataGridView
• ListView in VB.NET application
• How to implement Drag and Drop on a DataGridView ?
• Set Default value on new record in BindingSource / BindingNavigator scenario