일부 확인을 위해 주어진 각 열의 데이터 형식을 얻으려고합니다. 이미 getSchemaTable
을 시도했지만 값이없는 테이블의 스키마 만 제공합니다.SqlDataReader를 사용하여 열의 데이터 형식 및 크기를 얻는 방법?
예를 들어, 데이터베이스에 테이블이 있고 열 이름이 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);
답변을 자세히 설명해 주시겠습니까? – Stephan
나는 이것을 시도했다 : string Type = reader [ "id_declarant"]. GetFieldType (0) .FullName; 하지만 System.string을 표시합니다. – manu
유형 type = reader.GetFieldType (0); 문자열 대신 Type = reader [ "id_declarant"]. GetFieldType (0) .FullName; BTW, id_declarant의 데이터 유형은 무엇입니까? – ojlovecd