469,632 Members | 1,555 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 469,632 developers. It's quick & easy.

Mapping problem with ADO.NET


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);

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!!!

Mar 23 '06 #1
1 1547


Nevermind - situation resolved.

================================================== ============

On Thu, 23 Mar 2006 15:03:06 -0600, no**@no.com wrote:

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);

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!!!

Mar 24 '06 #2

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

2 posts views Thread by Frank | last post: by
20 posts views Thread by Pierre Fortin | last post: by
6 posts views Thread by naruto | last post: by
1 post views Thread by Tamas Hegedus | last post: by
3 posts views Thread by Elder Hyde | last post: by
6 posts views Thread by Michael Tissington | last post: by
1 post views Thread by Ram | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.