Determining Field Size

G

Guest

I am trying to find a simple way to determine the field size of a field in an Access table. I am writing in VB.NET Windows application. I would like a code snippet that I can get to work. I found some example on the Web but I couldn’t get them to work. I will be grateful if you can help me with this.
 
G

Guest

Hi Bob,

Foll. is the code snippet to get a datatable of schema values from your sql query.

private DataTable CreateSchema()
{
OleDbConnection conn=new OleDbConnection(@"provider=Microsoft.JET.OLEDB.4.0; data source=D:\User\Sanjay\SMSPress30\SmsPress\Data\db.mdd");
conn.Open();
OleDbCommand cmd=new OleDbCommand("select * from t_group",conn);
OleDbDataReader read= cmd.ExecuteReader();
DataTable dt=new DataTable();
dt=read.GetSchemaTable();
cmd.Dispose();
read.Close();
conn.Close();
conn.Dispose();
return dt;
}

To get the fieldsize of a particular column use the foll. code:
DataRow[] dr=dt.Select("ColumnName='GroupName'");
if(dr.Length > 0)
{
MessageBox.Show("Fieldsize is:" + dr[0]["ColumnSize"].ToString());
}
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top