Problem with Access-MemoField that contains Data > 255 characters

  • Thread starter Thread starter Oliver Krüger
  • Start date Start date
O

Oliver Krüger

Hi there!
When the Memo field of a Access Database is over 255 characters,
OleDbDataAdapter doesn't
fill well my DataTable (only the first 255 characters). I tried with
OleDbDataReader, GetChars and filling a StringBuilder, and it seems it
only has 255 characters; it doesn't reach the rest.

Please help!

oliver
 
U¿ytkownik "Oliver Krüger said:
Hi there!
When the Memo field of a Access Database is over 255 characters,
OleDbDataAdapter doesn't
fill well my DataTable (only the first 255 characters). I tried with
OleDbDataReader, GetChars and filling a StringBuilder, and it seems it
only has 255 characters; it doesn't reach the rest.


You have an error. In what way do you check string lenght? I have made small
snipped and it works ok:

using System;
using System.Data.OleDb;

namespace TestAccessMemo
{
class Class1
{
[STAThread]
static void Main(string[] args)
{
Test t = new Test();
t.ReadD();

System.Console.ReadLine();
}
}

class Test
{
OleDbConnection con = new OleDbConnection();
public Test()
{
con.ConnectionString = "Provider=Microsoft.Jet.OLEDB.4.0;" +
@"Data Source=E:\NoteDb.mdb";
}

public void ReadD()
{
OleDbCommand myC = new OleDbCommand("Select Notes From tblData");
myC.Connection = con;
con.Open();
OleDbDataReader dr = myC.ExecuteReader();
while(dr.Read())
{
string note = dr.GetString(0);
System.Console.WriteLine("Note in db: \n{0},\n{1} chars",
note, note.Length);
}
con.Close();
}
}
}

Regards,
Grzegorz
 
Grzegorz Danowski said:
U¿ytkownik "Oliver Krüger said:
Hi there!
When the Memo field of a Access Database is over 255 characters,
OleDbDataAdapter doesn't
fill well my DataTable (only the first 255 characters). I tried with
OleDbDataReader, GetChars and filling a StringBuilder, and it seems it
only has 255 characters; it doesn't reach the rest.


You have an error. In what way do you check string lenght? I have made
small snipped and it works ok:

using System;
using System.Data.OleDb;

namespace TestAccessMemo
{
class Class1
{
[STAThread]
static void Main(string[] args)
{
Test t = new Test();
t.ReadD();

System.Console.ReadLine();
}
}

class Test
{
OleDbConnection con = new OleDbConnection();
public Test()
{
con.ConnectionString = "Provider=Microsoft.Jet.OLEDB.4.0;" +
@"Data Source=E:\NoteDb.mdb";
}

public void ReadD()
{
OleDbCommand myC = new OleDbCommand("Select Notes From tblData");
myC.Connection = con;
con.Open();
OleDbDataReader dr = myC.ExecuteReader();
while(dr.Read())
{
string note = dr.GetString(0);
System.Console.WriteLine("Note in db: \n{0},\n{1} chars",
note, note.Length);
}
con.Close();
}
}
}

Regards,
Grzegorz

Hi Grzegorz
Thanks for your fast reply!!!

For my solution I use a DataAdapter :

internal void SQLQueryRead(string p_sSql, ref DataTable p_Data)
{
string sPath = @"database\ckdata.mdb";
string sConnectionString = @"Provider=Microsoft.Jet.OLEDB.4.0;Persist
Security Info=False;Data Source=" + sPath;

OleDbConnection oleDbConnection = new
OleDbConnection(sConnectionString);
OleDbDataAdapter oleDbDataAdapter = new OleDbDataAdapter(p_sSql,
oleDbConnection);
oleDbDataAdapter.Fill(p_Data);
oleDbConnection.Close();

//Only for testing
//The MemoCommon-Field contains a text string with 500 characters
//The Console.WriteLine() output is 255 :-(
try{
string myString = p_Data.Rows[0]["MemoCommon"].ToString();
Console.WriteLine(myString.Length.ToString());
}
catch{}
}
 
U¿ytkownik "Oliver Krüger said:
(...)

Hi Grzegorz
Thanks for your fast reply!!!

For my solution I use a DataAdapter :

internal void SQLQueryRead(string p_sSql, ref DataTable p_Data)
{
string sPath = @"database\ckdata.mdb";
string sConnectionString = @"Provider=Microsoft.Jet.OLEDB.4.0;Persist
Security Info=False;Data Source=" + sPath;

OleDbConnection oleDbConnection = new
OleDbConnection(sConnectionString);
OleDbDataAdapter oleDbDataAdapter = new OleDbDataAdapter(p_sSql,
oleDbConnection);
oleDbDataAdapter.Fill(p_Data);
oleDbConnection.Close();

//Only for testing
//The MemoCommon-Field contains a text string with 500 characters
//The Console.WriteLine() output is 255 :-(
try{
string myString = p_Data.Rows[0]["MemoCommon"].ToString();
Console.WriteLine(myString.Length.ToString());
}
catch{}
}

I have made another snippet (using DataTable):

using System;
using System.Data;
using System.Data.OleDb;

namespace TestAccessMemo
{
class Class1
{
[STAThread]
static void Main(string[] args)
{
Test t = new Test();
t.FillDataTable();

System.Console.ReadLine();
}
}

class Test
{
OleDbConnection con = new OleDbConnection();
public Test()
{
con.ConnectionString = "Provider=Microsoft.Jet.OLEDB.4.0;" +
@"Data Source=E:\NoteDb.mdb;Persist Security Info=False";
}

public void FillDataTable()
{
OleDbDataAdapter da = new OleDbDataAdapter("Select Notes From tblData",
con);
DataTable dt = new DataTable();
da.Fill(dt);

foreach(DataRow dr in dt.Rows)
{
string note = dr[0].ToString();
System.Console.WriteLine("Note in datatable:" +
"\n{0},\n{1} chars", note, note.Length);
}
}
}
}

And it works ok. Maybe you have an error in definition of your datatable
p_Data?
Regards,
Grzegorz
 
Grzegorz Danowski said:
U¿ytkownik "Oliver Krüger said:
(...)

Hi Grzegorz
Thanks for your fast reply!!!

For my solution I use a DataAdapter :

internal void SQLQueryRead(string p_sSql, ref DataTable p_Data)
{
string sPath = @"database\ckdata.mdb";
string sConnectionString = @"Provider=Microsoft.Jet.OLEDB.4.0;Persist
Security Info=False;Data Source=" + sPath;

OleDbConnection oleDbConnection = new
OleDbConnection(sConnectionString);
OleDbDataAdapter oleDbDataAdapter = new OleDbDataAdapter(p_sSql,
oleDbConnection);
oleDbDataAdapter.Fill(p_Data);
oleDbConnection.Close();

//Only for testing
//The MemoCommon-Field contains a text string with 500 characters
//The Console.WriteLine() output is 255 :-(
try{
string myString = p_Data.Rows[0]["MemoCommon"].ToString();
Console.WriteLine(myString.Length.ToString());
}
catch{}
}

I have made another snippet (using DataTable):

using System;
using System.Data;
using System.Data.OleDb;

namespace TestAccessMemo
{
class Class1
{
[STAThread]
static void Main(string[] args)
{
Test t = new Test();
t.FillDataTable();

System.Console.ReadLine();
}
}

class Test
{
OleDbConnection con = new OleDbConnection();
public Test()
{
con.ConnectionString = "Provider=Microsoft.Jet.OLEDB.4.0;" +
@"Data Source=E:\NoteDb.mdb;Persist Security Info=False";
}

public void FillDataTable()
{
OleDbDataAdapter da = new OleDbDataAdapter("Select Notes From tblData",
con);
DataTable dt = new DataTable();
da.Fill(dt);

foreach(DataRow dr in dt.Rows)
{
string note = dr[0].ToString();
System.Console.WriteLine("Note in datatable:" +
"\n{0},\n{1} chars", note, note.Length);
}
}
}
}

And it works ok. Maybe you have an error in definition of your datatable
p_Data?
Regards,
Grzegorz

Hi Grzegorz!

I have found the defect :-)
In the SQL-Statement I use a UNION for the Memo fields!

Best regards!

Oliver
 
Back
Top