Question

For some reason, I can't open the Design View of the MS Access table in question; I can look at the data but not the desing, specifically, the length of columns.

When I try to insert a record into said table with this code:

using (var conn = new OleDbConnection(connStr))
{
    using (var cmd = conn.CreateCommand())
    {
        cmd.CommandText = 
            @"INSERT INTO tx_header (tx, site_no, xmlfile, collect_dttm, ccr_user, tx_memo, file_beg, file_end) 
              VALUES(@txval, @siteNum, @xmlfileName, Now(), @ccrUser, @TXMemo, @strfile_beg, @strfile_end)";
        cmd.CommandType = CommandType.Text;
        cmd.Parameters.AddWithValue("@txval", tx);
        cmd.Parameters.AddWithValue("@siteNum", site_no);
        cmd.Parameters.AddWithValue("@xmlfileName", xmlfile);
        cmd.Parameters.AddWithValue("@ccrUser", ccr_user);
        cmd.Parameters.AddWithValue("@TXMemo", tx_memo);
        cmd.Parameters.AddWithValue("@strfile_beg", file_beg);
        cmd.Parameters.AddWithValue("@strfile_end", file_end);
        conn.Open();
        cmd.ExecuteNonQuery();
    }
}

...I get, "System.Data.OleDb.OleDbException was unhandled by user code HResult=-2147217833 Message=The field is too small to accept the amount of data you attempted to add. Try inserting or pasting less data. Source=Microsoft Office Access Database Engine"

Rather than have to guess which column has too much data, it would be nice if I could programmatically determine which column is the problematic one. Can I? How?

Was it helpful?

Solution

There's a pretty detailed explanation of how to query the underlying schema information in MSDN, starting at Retrieving Database Schema Information.

Disclaimer: I've never tried using that against an Access database.

OTHER TIPS

After reading your comments above it looks clear to me that your Access file simply has its designer views locked down. Normally you should be able to unlock them by simply holding Shift, double-clicking the file and keep holding Shift until Access is up and running.

From then on you'll have complete access to tables, queries and the like, and along with it, your database specifications. That will be far better than trying to access that dynamically.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top