Hi guys,
I am inserting value from xml file to access database the file is near about 6 MB (size not problem) but the file contains mathematics questions containing images(jpeg,bmp),equations(math type) so while inserting some questions it will give an error "Query Is Too Complex "

can anybody tell me how to resolve this thread.....
Thanks in advance.

Dani AI

Generated

Short, practical diagnosis and fixes that complement the existing replies from and .

Access’s “Query is too complex” is the Jet/ACE engine runtime message (error 3360) that usually means the SQL parser hit internal complexity limits — nested expressions/IIfs, very long SQL, many UNIONs or lots of calculated columns — not necessarily a syntax bug in C# alone. ’s join-limit idea is one common cause for SELECTs, but an INSERT built by concatenation can hit other parser limits. (fmsinc.com)

For this XML import that contains images and MathType content, the usual problems are: the concatenated INSERT becomes extremely long or contains unescaped quotes/special bytes; attempting to shove OLE/Attachment content directly into a VALUES clause; or using the wrong Access field type (Short Text vs Long Text / OLE Object / Attachment). First debug by writing the final SQL string to a log file and try inserting one minimal row (no image, plain ASCII) — that isolates which field triggers the failure. Also follow ’s advice: explicitly name the target columns in the INSERT. (stackoverflow.com)

Definitive fixes (apply in this order):

  • Stop building SQL by string concatenation; use parameterized OleDbCommand with positional ? placeholders (order of parameters matters for OleDb).
  • Pass text as parameters (memo/Long Text for long question text) and images as byte[] parameters with OleDbType.Binary (store images in an OLE Object/IMAGE column or handle Attachment fields specially). Example pattern:
    cmd.CommandText = "INSERT INTO starttest (colA,colB,...,question,imagecol) VALUES (?,?,?,?,?,?)";
    cmd.Parameters.Add(new OleDbParameter { OleDbType = OleDbType.Integer, Value = kl });
    cmd.Parameters.Add(new OleDbParameter { OleDbType = OleDbType.VarWChar, Value = testno ?? (object)DBNull.Value });
    ...
    cmd.Parameters.Add(new OleDbParameter { OleDbType = OleDbType.Binary, Value = imageBytes ?? (object)DBNull.Value });
    cmd.ExecuteNonQuery();

    Using parameters avoids SQL parser trouble and fixes quoting/size problems. (learn.microsoft.com)

If the table uses Access’s Attachment (multi-valued) fields, a plain INSERT won’t work — those need DAO or the Attachment-specific approach (or a small binary header hack used by some helpers). For large-scale imports, consider storing images as files and save paths in Access (or migrate heavy data to SQL Server/ACE backend) to avoid bloating the .mdb/.accdb. (stackoverflow.com)

Troubleshooting checklist: log the generated SQL; try a simplified insert; convert image insertion to parameterized binary; confirm target column data types (Long Text / OLE/Attachment); and avoid embedding connection creation inside each command — open once, reuse the command + parameters for each row.

Recommended Answers

All 4 Replies

Access has a limit of 16 JOINs and that error appears when you have exceeded that limit. You'll need to find a way to reduce the number before it will work.

Hi,
table contains 12 fields and doesn't using the join it's plain insert query.

string insertstt = "insert into starttest values (" + kl + ",'" + testno + "'," + que_id + "," + subcode + "," + chapcode + ",'" + que + "','" + opt1 + "','" + opt2 + "','" + opt3 + "','" + opt4 + "','" + ans + "','" + solution + "')";

Ocmd = new OleDbCommand(insertstt, Connect.AccConn());

Have you looked at the resulting string after it is concatenated?
It may be worse than you think.

Also, you should not init-and-embed your connection inside your command.

Also, a statement like that makes an assumption about columnn order.
It might make it easier for the parser if you name the columns and then the values

INSERT INTO starttest(col1, col2, col3) VALUES(val1, val2, val3)
Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.