N
none
Hi,
I'm trying to establish table mappings, and I've hit a snag.
At the point to where I try to fill the schema (DB_adapter.FillSchema),
I get an exception, and the message is as follows:
::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
Invalid column name 'Unique_ref'.
Invalid column name 'ID_string'.
Invalid column name 'Sequence'.
::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
I don't get it. Why doesn't it use the mapping?
I'm probably doing something dumb, so feel free to call me names
and gloat over my inferior mental capacity.
I'm using ASP.NET version 2.0.
My code is as follows:
::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
private SqlConnection sql_connctn;
private SqlDataAdapter DB_adapter;
private DataTable Ctrl_ID_key_set_table;
private bool connctn_OK;
private const string
SQL_DB_server = "COMP-NAME-BASIC\\SQL2005DEV";
private const string
SQL_DB = "Init01";
private const string
DB_ctrl_struct_table_name = "dbo.Ctrl_Init_Struct01";
private const string
ctrl_struct_table_name = "Ctrl_Init_Struct01";
private const string
select_cmdstr = @"SELECT Unique_ref, ID_string, Sequence FROM ";
/* =============================================== */
/* =============================================== */
private SqlConnection Get_new_SQL_conn
{ get {
SqlConnectionStringBuilder
builder = new SqlConnectionStringBuilder ();
builder["Data Source"] = SQL_DB_server;
builder["Initial Catalog"] = SQL_DB;
builder["Integrated Security"] = "SSPI";
return
sql_connctn = new SqlConnection (builder.ConnectionString);
} }
/* =============================================== */
/* =============================================== */
private bool get_DB_adapter (string p_table_name)
{
bool adapter_created_ok;
SqlCommandBuilder builder;
try
{
DB_adapter
= new SqlDataAdapter
(select_cmdstr + p_table_name, sql_connctn);
builder = new SqlCommandBuilder(DB_adapter);
adapter_created_ok = true;
}
catch
{ adapter_created_ok = false; }
return adapter_created_ok;
}
/* =============================================== */
/* =============================================== */
private DataTableMapping get_struct_mapping
{ get {
DataTableMapping
mapping = new DataTableMapping
(ctrl_struct_table_name, ctrl_struct_table_name);
mapping.ColumnMappings.Add
("DB_Unique_ref", "Unique_ref");
mapping.ColumnMappings.Add
("DB_ID_string", "ID_string");
mapping.ColumnMappings.Add
("DB_Sequence", "Sequence");
return mapping;
} }
/* =============================================== */
/* =============================================== */
private bool DBtable_for_struct_datatable ()
{
try
{
using (Get_new_SQL_conn)
{
sql_connctn.Open ();
if (get_DB_adapter (DB_ctrl_struct_table_name))
{
DB_adapter.TableMappings.Add (get_struct_mapping);
Ctrl_ID_key_set_table
= new DataTable (ctrl_struct_table_name);
// exception thrown after this ...
schema_datatable
= DB_adapter.FillSchema
(Ctrl_ID_key_set_table, SchemaType.Mapped);
connctn_OK = true;
}
else connctn_OK = false;
}
}
catch
{ connctn_OK = false; }
return connctn_OK;
}
/* =============================================== */
/* =============================================== */
::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
THANKS!!!
I'm trying to establish table mappings, and I've hit a snag.
At the point to where I try to fill the schema (DB_adapter.FillSchema),
I get an exception, and the message is as follows:
::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
Invalid column name 'Unique_ref'.
Invalid column name 'ID_string'.
Invalid column name 'Sequence'.
::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
I don't get it. Why doesn't it use the mapping?
I'm probably doing something dumb, so feel free to call me names
and gloat over my inferior mental capacity.
I'm using ASP.NET version 2.0.
My code is as follows:
::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
private SqlConnection sql_connctn;
private SqlDataAdapter DB_adapter;
private DataTable Ctrl_ID_key_set_table;
private bool connctn_OK;
private const string
SQL_DB_server = "COMP-NAME-BASIC\\SQL2005DEV";
private const string
SQL_DB = "Init01";
private const string
DB_ctrl_struct_table_name = "dbo.Ctrl_Init_Struct01";
private const string
ctrl_struct_table_name = "Ctrl_Init_Struct01";
private const string
select_cmdstr = @"SELECT Unique_ref, ID_string, Sequence FROM ";
/* =============================================== */
/* =============================================== */
private SqlConnection Get_new_SQL_conn
{ get {
SqlConnectionStringBuilder
builder = new SqlConnectionStringBuilder ();
builder["Data Source"] = SQL_DB_server;
builder["Initial Catalog"] = SQL_DB;
builder["Integrated Security"] = "SSPI";
return
sql_connctn = new SqlConnection (builder.ConnectionString);
} }
/* =============================================== */
/* =============================================== */
private bool get_DB_adapter (string p_table_name)
{
bool adapter_created_ok;
SqlCommandBuilder builder;
try
{
DB_adapter
= new SqlDataAdapter
(select_cmdstr + p_table_name, sql_connctn);
builder = new SqlCommandBuilder(DB_adapter);
adapter_created_ok = true;
}
catch
{ adapter_created_ok = false; }
return adapter_created_ok;
}
/* =============================================== */
/* =============================================== */
private DataTableMapping get_struct_mapping
{ get {
DataTableMapping
mapping = new DataTableMapping
(ctrl_struct_table_name, ctrl_struct_table_name);
mapping.ColumnMappings.Add
("DB_Unique_ref", "Unique_ref");
mapping.ColumnMappings.Add
("DB_ID_string", "ID_string");
mapping.ColumnMappings.Add
("DB_Sequence", "Sequence");
return mapping;
} }
/* =============================================== */
/* =============================================== */
private bool DBtable_for_struct_datatable ()
{
try
{
using (Get_new_SQL_conn)
{
sql_connctn.Open ();
if (get_DB_adapter (DB_ctrl_struct_table_name))
{
DB_adapter.TableMappings.Add (get_struct_mapping);
Ctrl_ID_key_set_table
= new DataTable (ctrl_struct_table_name);
// exception thrown after this ...
schema_datatable
= DB_adapter.FillSchema
(Ctrl_ID_key_set_table, SchemaType.Mapped);
connctn_OK = true;
}
else connctn_OK = false;
}
}
catch
{ connctn_OK = false; }
return connctn_OK;
}
/* =============================================== */
/* =============================================== */
::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
THANKS!!!