Missing SourceColumn mapping?!

  • Thread starter Thread starter Val
  • Start date Start date
V

Val

Hi all,
having trouble with an Access database, it has a table "Books", the program
uses a dataset to work with the database.
I set up the schema for the table "Books" as follows:

(C#)
////////////////////////////
m_dataset.Tables.Add("Books");
DataColumn PrimaryKeyColumn =
m_dataset.Tables["Books"].Columns.Add("ID",typeof(int));
m_dataset.Tables["Books"].PrimaryKey = new DataColumn[] {PrimaryKeyColumn};
m_dataset.Tables["Books"].Columns.Add("Name",typeof(string));
m_dataset.Tables["Books"].Columns.Add("ISBN",typeof(string));
m_dataset.Tables["Books"].Columns.Add("Price",typeof(float));
m_dataset.Tables["Books"].Columns.Add("iStock",typeof(int));
m_dataset.Tables["Books"].Columns.Add("mStock",typeof(int));
m_dataset.Tables["Books"].Columns.Add("Barcode",typeof(string));
m_dataset.Tables["Books"].Columns.Add("Description",typeof(string));
////////////////////////////

and then everytime i try to fill it with the dataadapter an exeption
"Missing SourceColumn mapping for 'ID' " is thrown.
Im totaly in the dark with this one, nothing I try makes any difference, any
help would be great!

Val
 
Hi:
Do you define The Id'mapping with DataSource?
Id=new System.Data.DataColumn("Id");
 
Do you define The Id'mapping with DataSource?

Not sure what you mean by defining mapping through DataSource,
im not using a DataGrid (or any Forms control for that matter, its just a
comand prompt interface at the moment).
Id=new System.Data.DataColumn("Id");

This is exactly the same thing as mine "DataColumn PrimaryKeyColumn =
m_dataset.Tables["Books"].Columns.Add("ID",typeof(int));", I think :]
 
You haven't shown how you link the dataadapter to this table. The error
message is telling you that the data adapter doesn't know what column in the
datatable belongs to what column in the database. You can code
"tablemappings" and "columnmappings" - but that would be doing it the hard
way.

If there is a table that you want to use with this dataset you are creating
you are trying to do this the hard way. All you need is:

Dim da as OleDbDataAdapter ("SELECT * FROM BOOKS, connection)
da.fill(m_dataset, "Books")

You don't need to define all the columns, etc. in the datatable - The data
adapter will do it for you, based on the information it derives from its
SELECT statement.
You may still want to define a primary key, if you need it.

Good Luck
 
Back
Top