Column Length
-
I'm using ADO.NET and I'm attempting to get the column length for VARCHAR columns using the MaxLength property of the DataTable class, but it always returns -1, any secrets to finding this info from a returned MS SQL Server Query ?
-
I'm using ADO.NET and I'm attempting to get the column length for VARCHAR columns using the MaxLength property of the DataTable class, but it always returns -1, any secrets to finding this info from a returned MS SQL Server Query ?
According to the docs "If the column has no maximum length, the value is –1 (default)." If you set MaxLength on a column do you still get -1 back? Mark
-
According to the docs "If the column has no maximum length, the value is –1 (default)." If you set MaxLength on a column do you still get -1 back? Mark
Yes, the length limit can be seen in the "Design Table" dialog of the SQL Server Enterprise Manager for the table in question. Its a VARCHAR(50) column, but after I query this tabkle the DataTable's DataColumn has a MaxLength value of -1 Here is the code i use to Query the Table if that helps...
DataTable DT = new DataTable();
if(m_DB is SqlConnection)
{
m_DA = new SqlDataAdapter(Query,(SqlConnection)m_DB);
m_CB = new SqlCommandBuilder((SqlDataAdapter)m_DA);
((SqlCommandBuilder)m_CB).QuotePrefix="[";
((SqlCommandBuilder)m_CB).QuoteSuffix="]";
((SqlDataAdapter)m_DA).Fill(DT);
} -
Yes, the length limit can be seen in the "Design Table" dialog of the SQL Server Enterprise Manager for the table in question. Its a VARCHAR(50) column, but after I query this tabkle the DataTable's DataColumn has a MaxLength value of -1 Here is the code i use to Query the Table if that helps...
DataTable DT = new DataTable();
if(m_DB is SqlConnection)
{
m_DA = new SqlDataAdapter(Query,(SqlConnection)m_DB);
m_CB = new SqlCommandBuilder((SqlDataAdapter)m_DA);
((SqlCommandBuilder)m_CB).QuotePrefix="[";
((SqlCommandBuilder)m_CB).QuoteSuffix="]";
((SqlDataAdapter)m_DA).Fill(DT);
}Ok, sorry. I use ODBC to get schema info in my database code, specifically SQLTables() and SQLColumns(). Take a look at GetSchemaTable (in DataReader). I'm pretty sure that retreives the same info as the ODBC functions. I think it's tough to use a specific SQL query because the way schema is stored varies by server, version, etc. Mark