S
Supel
I have problem with insert and update record by OleDb in Access. I have
table test with 151 columns and I can insert or update record.
I have 2 exception error
1. "Record is too long" when I try to insert
2. "Too many name columns" in update query
Somebody can help me and explain where is error?
Has OleDb max number parameters and max size record in query updet or
insert??
Thanks.
Robert
There are example code:
void Init()//Main function
{
OleDbConnection myConnect = Connect();
try
{
//HERE ARE ERRORS!!! when a can insert or update
InsertTable(myConnect);
//or
UpdateTable(myConnect);
}
catch(System.Exception e2)
{
e2=e2;
}
finally
{ if(myConnect!=null)
myConnect.Close();
}
}
const int MAX_COLUMN_TO_UPDATE = 15;
const int MAX_COLUMN_TO_INSERT = 150;
OleDbConnection Connect()
{ OleDbConnection myConn = null;
myConn = new OleDbConnection(ConnStr);
myConn.Open();
return myConn;
}
string ConnStr = "Provider=Microsoft.Jet.OLEDB.4.0;User ID=Admin;Data
Source=D:\\test.mdb;Mode=ReadWrite|Share Deny None;Jet OLEDB:Engine
Type=5;Jet OLEDBatabase Locking Mode=1;Jet OLEDB:Global Partial Bulk
Ops=2;Jet OLEDB:Global Bulk Transactions=1;Jet OLEDB:Create System
Database=False;Jet OLEDB:Encrypt Database=False;Jet OLEDBon't Copy Locale
on Compact=False;Jet OLEDB:Compact Without Replica Repair=False;Jet
OLEDB:SFP=False;";
void CreateTable( OleDbConnection myConnect)
{ StringBuilder StrQuery = new StringBuilder(1000);
StrQuery.Append("create table test1 (unq int");
for(int i=0;i<MAX_COLUMN_TO_INSERT;i++)
StrQuery.AppendFormat(",kol{0} text(100)",i+1);
StrQuery.Append(")");
OleDbCommand myCommand = new OleDbCommand(StrQuery.ToString(),myConnect);
myCommand.ExecuteNonQuery();
}
void InsertTable( OleDbConnection myConnect)
{ OleDbCommand myCommand = new OleDbCommand("",myConnect);
StringBuilder StrQuery = new StringBuilder(1000);
StrQuery.Append("INSERT INTO test1 (unq");
for(int i=0;i<MAX_COLUMN_TO_INSERT;i++)
StrQuery.AppendFormat(",kol{0}",i+1);
StrQuery.Append(") VALUES(?");
OleDbParameter Par = new OleDbParameter("unq", OleDbType.Integer);
Par.Value = 0;
myCommand.Parameters.Add(Par);
for(int i=0;i<MAX_COLUMN_TO_INSERT;i++)
{ StrQuery.Append(",?");
// OleDbParameter Par = new OleDbParameter(string.Format("(kol{1}",i+1),
OleDbType.VarChar,)
OleDbParameter Par1 = new
OleDbParameter(string.Format("kol{0}",i+1),"123456789_123456789_123456789_123456789_123456789_123456789_123456789_123456789_123456789_123456789_");
myCommand.Parameters.Add(Par1);
}
StrQuery.Append(")");
myCommand.CommandText = StrQuery.ToString();
myCommand.ExecuteNonQuery();
}
void UpdateTable( OleDbConnection myConnect)
{ OleDbCommand myCommand = new OleDbCommand("",myConnect);
StringBuilder StrQuery = new StringBuilder(1000);
StrQuery.Append("UPDATE test1 SET ");
for(int i=0;i<MAX_COLUMN_TO_UPDATE;i++)
{ if(i!=0)
StrQuery.Append(",");
StrQuery.AppendFormat("kol{0}=?",i+1);
OleDbParameter Par1 = new OleDbParameter(string.Format("kol{0}",i+1),"1");
myCommand.Parameters.Add(Par1);
}
StrQuery.Append("WHERE unq=?");
OleDbParameter Par = new OleDbParameter("unq", OleDbType.Integer);
Par.Value = 1;
myCommand.Parameters.Add(Par);
myCommand.CommandText = StrQuery.ToString();
myCommand.ExecuteNonQuery();
}
table test with 151 columns and I can insert or update record.
I have 2 exception error
1. "Record is too long" when I try to insert
2. "Too many name columns" in update query
Somebody can help me and explain where is error?
Has OleDb max number parameters and max size record in query updet or
insert??
Thanks.
Robert
There are example code:
void Init()//Main function
{
OleDbConnection myConnect = Connect();
try
{
//HERE ARE ERRORS!!! when a can insert or update
InsertTable(myConnect);
//or
UpdateTable(myConnect);
}
catch(System.Exception e2)
{
e2=e2;
}
finally
{ if(myConnect!=null)
myConnect.Close();
}
}
const int MAX_COLUMN_TO_UPDATE = 15;
const int MAX_COLUMN_TO_INSERT = 150;
OleDbConnection Connect()
{ OleDbConnection myConn = null;
myConn = new OleDbConnection(ConnStr);
myConn.Open();
return myConn;
}
string ConnStr = "Provider=Microsoft.Jet.OLEDB.4.0;User ID=Admin;Data
Source=D:\\test.mdb;Mode=ReadWrite|Share Deny None;Jet OLEDB:Engine
Type=5;Jet OLEDBatabase Locking Mode=1;Jet OLEDB:Global Partial Bulk
Ops=2;Jet OLEDB:Global Bulk Transactions=1;Jet OLEDB:Create System
Database=False;Jet OLEDB:Encrypt Database=False;Jet OLEDBon't Copy Locale
on Compact=False;Jet OLEDB:Compact Without Replica Repair=False;Jet
OLEDB:SFP=False;";
void CreateTable( OleDbConnection myConnect)
{ StringBuilder StrQuery = new StringBuilder(1000);
StrQuery.Append("create table test1 (unq int");
for(int i=0;i<MAX_COLUMN_TO_INSERT;i++)
StrQuery.AppendFormat(",kol{0} text(100)",i+1);
StrQuery.Append(")");
OleDbCommand myCommand = new OleDbCommand(StrQuery.ToString(),myConnect);
myCommand.ExecuteNonQuery();
}
void InsertTable( OleDbConnection myConnect)
{ OleDbCommand myCommand = new OleDbCommand("",myConnect);
StringBuilder StrQuery = new StringBuilder(1000);
StrQuery.Append("INSERT INTO test1 (unq");
for(int i=0;i<MAX_COLUMN_TO_INSERT;i++)
StrQuery.AppendFormat(",kol{0}",i+1);
StrQuery.Append(") VALUES(?");
OleDbParameter Par = new OleDbParameter("unq", OleDbType.Integer);
Par.Value = 0;
myCommand.Parameters.Add(Par);
for(int i=0;i<MAX_COLUMN_TO_INSERT;i++)
{ StrQuery.Append(",?");
// OleDbParameter Par = new OleDbParameter(string.Format("(kol{1}",i+1),
OleDbType.VarChar,)
OleDbParameter Par1 = new
OleDbParameter(string.Format("kol{0}",i+1),"123456789_123456789_123456789_123456789_123456789_123456789_123456789_123456789_123456789_123456789_");
myCommand.Parameters.Add(Par1);
}
StrQuery.Append(")");
myCommand.CommandText = StrQuery.ToString();
myCommand.ExecuteNonQuery();
}
void UpdateTable( OleDbConnection myConnect)
{ OleDbCommand myCommand = new OleDbCommand("",myConnect);
StringBuilder StrQuery = new StringBuilder(1000);
StrQuery.Append("UPDATE test1 SET ");
for(int i=0;i<MAX_COLUMN_TO_UPDATE;i++)
{ if(i!=0)
StrQuery.Append(",");
StrQuery.AppendFormat("kol{0}=?",i+1);
OleDbParameter Par1 = new OleDbParameter(string.Format("kol{0}",i+1),"1");
myCommand.Parameters.Add(Par1);
}
StrQuery.Append("WHERE unq=?");
OleDbParameter Par = new OleDbParameter("unq", OleDbType.Integer);
Par.Value = 1;
myCommand.Parameters.Add(Par);
myCommand.CommandText = StrQuery.ToString();
myCommand.ExecuteNonQuery();
}