c#里边怎么获得access数据库中某一张表某一字段的类型?
1个回答
展开全部
using System;
using System.Collections.Generic;
using System.Text;
using System.Data.OleDb;
using System.Data;
namespace zjh
{
class Program
{
static void Main(string[] args)
{
OleDbConnection conn = new OleDbConnection();
conn.ConnectionString = "输入连接字符串";
OleDbDataAdapter adp = new OleDbDataAdapter("select * from TableName", conn);
DataTable dt = new DataTable();
conn.Open();
adp.Fill(dt);
conn.Close();
Type t = dt.Columns["列名"].DataType;
Console.WriteLine(t);
Console.ReadLine();
}
}
}
using System.Collections.Generic;
using System.Text;
using System.Data.OleDb;
using System.Data;
namespace zjh
{
class Program
{
static void Main(string[] args)
{
OleDbConnection conn = new OleDbConnection();
conn.ConnectionString = "输入连接字符串";
OleDbDataAdapter adp = new OleDbDataAdapter("select * from TableName", conn);
DataTable dt = new DataTable();
conn.Open();
adp.Fill(dt);
conn.Close();
Type t = dt.Columns["列名"].DataType;
Console.WriteLine(t);
Console.ReadLine();
}
}
}
追问
假如某一字段是varchar类型的,怎么获取这个字段的最大字符数呢?
追答
select
o.name as tbname,
c.name as columnname,
t.name as typename,
c.max_length
from sys.tables as o
join sys.columns as c
on o.object_id=c.object_id
join sys.types as t
on c.system_type_id=t.system_type_id
输出这些行数即可
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询