【发布时间】:2013-06-24 08:33:53
【问题描述】:
我正在尝试获取给定的每一列的数据类型以进行一些验证
我已经尝试过getSchemaTable,但它只给了我一个没有值的表的架构。
例如,我的数据库中有一个表和一个列名:id_declarant。
我想从id_declarant 中检索一个值的数据类型和大小。
这里是代码:
comm.Connection=new SqlConnection(connectionString);
String sql = @"
SELECT *
FROM id_declarant,declarant
WHERE (declarant.Nom_pren_RS='" + textBox1.Text + "')
and (id_declarant.mat_fisc=declarant.mat_fisc) ";
comm.CommandText = sql;
comm.Connection.Open();
string mat_fisc;
string clé_mat_fisc;
string categorie ;
string num_etab_sec ;
string activite;
StringBuilder sb = new StringBuilder();
String Nom = textBox1.Text;
using (SqlDataReader reader = comm.ExecuteReader())
{
while (reader.Read())
{
//here i want to know how to retrieve the reader[0].Type and Size to do the verification
mat_fisc = reader[0].ToString();
clé_mat_fisc = reader["clé_mat_fisc"].ToString();
categorie = reader["categorie"].ToString();
num_etab_sec = reader["num_etab_sec"].ToString();
activite = reader["activite"].ToString();
sb.Append("EF" + mat_fisc + clé_mat_fisc + categorie + num_etab_sec + textBox2.Text + textBox3.Text + Nom + activite);
【问题讨论】:
标签: c# .net database getschematable