Wrox Programmer Forums
Go Back   Wrox Programmer Forums > .NET > Other .NET > ADO.NET
|
ADO.NET For discussion about ADO.NET.  Topics such as question regarding the System.Data namespace are appropriate.  Questions specific to a particular application should be posted in a forum specific to the application .
Welcome to the p2p.wrox.com Forums.

You are currently viewing the ADO.NET section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
 
Old August 16th, 2004, 01:20 PM
Authorized User
 
Join Date: Aug 2004
Posts: 11
Thanks: 0
Thanked 0 Times in 0 Posts
Default dataset column not in data base table

I have been struggling with inserting a row into a simple bridge table for the past while and though this would be dead simple in VB6 this process in .Net is getting me down.

Thanks to Bmains I finally got a different error message that makes some sense but no light is shining on the problem with my ocde as far as I can tell.

 The message now is:

System.InvalidOperationException: Missing the datacolumn "Survey_Id" in the datatable "Bridge" for the sourcecolumn "survey_id"

~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Private Sub linkProject(ByVal surveyid As Integer)
        Dim querystring As String
        Dim myrow As DataRow
        Dim bridgeinsert As String

        querystring = "Select organisation_id_fk,Survey_id_fk from surveyorganisationbridge"
        bridgeinsert = "Insert into surveyorganisationbridge (Organisation_Id_Fk,Survey_Id_Fk) values (?,?) "

        OledbDataConn.Open()


        daSurvey.SelectCommand.commantext = querystring
        daSurvey.Fill(dsSurvey, "Bridge")

        myrow = dsSurvey.Tables("Bridge").NewRow
        myrow("Organisation_Id_Fk") = CInt(Me.tvPostField.SelectedNode.Tag)
        myrow("Survey_Id_Fk") = CInt(surveyid)

        dsSurvey.Tables("Bridge").Rows.Add(myrow)

        daSurvey.Update(dsSurvey, "Bridge")

        OledbDataConn.Close()

    End Sub
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~`
But there isn't such a column in the table! Both columns are foreign keys for the ids of two other tables.

The dataadapter and datset are global and I have popuated the access data base table with survey information prior to inserting the row in the brige table. Also the organisation id in the orgainsation table exists already.

There is something going on that I do not understand. I have tried to do this 4 different ways (mapping tables, making associations etc) all without success. I am able to insert data into a table but there is something else going on.

Help please.

Guy Buller
Project Module Leader
Geological
Survey of Canada
__________________
Guy
 
Old August 16th, 2004, 02:34 PM
Authorized User
 
Join Date: Aug 2004
Posts: 11
Thanks: 0
Thanked 0 Times in 0 Posts
Default

After more hair pulling I got the answer....not what I expected and proves to me why dotNet, like all other wizards, are evil!

To solve my problem I had to create a new instance of the command builder object to "clean out" the commands that were built automatically by the application.

Thus the line

dim cmdBuilder as New OledbcommandBuilder(dsSurveys) is the answer.

Guy Buller
Project Module Leader
Geological
Survey of Canada
 
Old August 17th, 2004, 10:15 AM
planoie's Avatar
Friend of Wrox
 
Join Date: Aug 2003
Posts: 5,407
Thanks: 0
Thanked 16 Times in 16 Posts
Default

.NET is actually quite not evil if you don't use the "wizards".
 
Old August 18th, 2004, 10:17 PM
Authorized User
 
Join Date: Aug 2004
Posts: 14
Thanks: 0
Thanked 0 Times in 0 Posts
Default

daSurvey.Update(dsSurvey, "Bridge")

by using the Update u must have ur own InsertCommand in ur DataAdapter.
eg.

OleDbCommand com;
com = new OleDbCommand();

com.Parameters.Add("@ID", OleDbType.VarChar , 50, "DeptID");

com.CommandText = "Insert into MS_Test (ID) Values (@ID)";

da.InsertCommand = com;



~ Human Knowledge Belongs to the World !
 
Old August 18th, 2004, 10:18 PM
Authorized User
 
Join Date: Aug 2004
Posts: 14
Thanks: 0
Thanked 0 Times in 0 Posts
Default

It's not an evil, it's just u are not used to it only.

~ Human Knowledge Belongs to the World !





Similar Threads
Thread Thread Starter Forum Replies Last Post
Data Base Error anees ASP.NET 1.0 and 1.1 Professional 6 May 27th, 2008 09:02 AM
Table data is Right, DataSet is Wrong Charlie05 VB Databases Basics 1 August 21st, 2007 09:04 PM
Dataset and data Table Queations maddy137 ASP.NET 1.0 and 1.1 Professional 4 August 30th, 2006 02:33 AM
Transfering data from csv file to data base g_vamsi_krish ASP.NET 1.0 and 1.1 Professional 2 May 16th, 2006 11:58 PM
how to make column of table 1 = to column of table gilgalbiblewheel Classic ASP Databases 4 October 11th, 2004 11:57 PM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.