Crud DataTable code is bombing

This forum is for programmers who have questions about the source code.
Post Reply
User avatar
wjstarck
Posts: 936
Joined: Tue Jul 31, 2007 7:18 am
Location: Keller, TX
Contact:

Crud DataTable code is bombing

Post by wjstarck » Fri May 21, 2010 11:23 am

This is bombing on the plugin but I'm not sure why:

Code: Select all

		///<summary>Converts a DataTable to a list of objects.</summary>
		internal static List<AnesthMedsInventory> TableToList(DataTable table){
			List<AnesthMedsInventory> retVal=new List<AnesthMedsInventory>();
			AnesthMedsInventory anesthmedsinventory;
			for(int i=0;i<table.Rows.Count;i++) {
				anesthmedsinventory=new AnesthMedsInventory();
				anesthmedsinventory.AnestheticMedNum = PIn.Long(table.Rows[i]["AnestheticMedNum"].ToString());
				anesthmedsinventory.AnesthMedName = PIn.String(table.Rows[i]["AnesthMedName"].ToString());
				anesthmedsinventory.AnesthHowSupplied = PIn.String(table.Rows[i]["AnesthHowSupplied"].ToString());
				anesthmedsinventory.QtyOnHand = PIn.String(table.Rows[i]["QtyOnHand"].ToString());
				anesthmedsinventory.DEASchedule = PIn.String(table.Rows[i]["DEASchedule"].ToString());
				retVal.Add(anesthmedsinventory);
			}
			return retVal;
		}
The exception I'm getting is 'Column 'AnestheticMedNum' is not part of table' whenever I call a method that in turn calls TableToList. Any ideas?
Cheers,

Bill Starck, DDS
Big Idea Software, LLC
Developer, EASy(Electronic Anesthesia System) for Open Dental
817-807-1709
TX, USA

User avatar
jordansparks
Site Admin
Posts: 5742
Joined: Sun Jun 17, 2007 3:59 pm
Location: Salem, Oregon
Contact:

Re: Crud DataTable code is bombing

Post by jordansparks » Fri May 21, 2010 12:08 pm

I don't see that code anywhere. So that must be your code, right? Did you generate it by inheriting your class from TableBase? And then you're trying to use that generated code? I would also have to see the schema for your table to debug that issue. Make sure capitalization is correct. Are you sure it's not AnestheticMedsNum, for example? (with an s).
Jordan Sparks, DMD
http://www.opendental.com

User avatar
wjstarck
Posts: 936
Joined: Tue Jul 31, 2007 7:18 am
Location: Keller, TX
Contact:

Re: Crud DataTable code is bombing

Post by wjstarck » Sat May 22, 2010 8:49 am

Here is the code for that table:

Code: Select all

using System;
using System.Collections;
using OpenDentBusiness;

namespace Anesthesia
{
    /// <summary>The names and inventory counts of all scheduled anesthetic medications stored on premises </summary>
    [Serializable()]
    public class AnesthMedsInventory : TableBase {

        [CrudColumn(IsPriKey = true)]
        ///<summary>Primary Key</summary>
        public long AnestheticMedNum;
        public string AnesthMedName;
        public string AnesthHowSupplied;
        public string QtyOnHand;
        public string DEASchedule;

        public AnesthMedsInventory Copy()
        {
            return (AnesthMedsInventory)this.MemberwiseClone();
        }

    }
}
I don't see any typos.

How are you generating your CRUD templates?
Cheers,

Bill Starck, DDS
Big Idea Software, LLC
Developer, EASy(Electronic Anesthesia System) for Open Dental
817-807-1709
TX, USA

User avatar
jordansparks
Site Admin
Posts: 5742
Joined: Sun Jun 17, 2007 3:59 pm
Location: Salem, Oregon
Contact:

Re: Crud DataTable code is bombing

Post by jordansparks » Sat May 22, 2010 11:45 am

Almost there. Now, I'd have to see the code that created the DataTable as well as the actual database schema. The database schema is not the one you just provided. It's the one generated by MySQL. Here's an example from another table:
CREATE TABLE `covcat` (
`CovCatNum` bigint(20) NOT NULL auto_increment,
`Description` varchar(50) default '',
`DefaultPercent` tinyint(3) NOT NULL default '0',
`CovOrder` tinyint(3) unsigned NOT NULL default '0',
`IsHidden` tinyint(1) unsigned NOT NULL default '0',
`EbenefitCat` tinyint(3) unsigned NOT NULL default '0',
PRIMARY KEY (`CovCatNum`)
) ENGINE=MyISAM DEFAULT CHARSET=utf8
Jordan Sparks, DMD
http://www.opendental.com

User avatar
jordansparks
Site Admin
Posts: 5742
Joined: Sun Jun 17, 2007 3:59 pm
Location: Salem, Oregon
Contact:

Re: Crud DataTable code is bombing

Post by jordansparks » Sat May 22, 2010 11:45 am

We generate our crud files by running the crud project in the solution. But I wouldn't expect you to do that. We only gain efficiency because of the scale.
Jordan Sparks, DMD
http://www.opendental.com

User avatar
wjstarck
Posts: 936
Joined: Tue Jul 31, 2007 7:18 am
Location: Keller, TX
Contact:

Re: Crud DataTable code is bombing

Post by wjstarck » Sat May 22, 2010 12:06 pm

Oh, OK.

Here's the schema:

CREATE TABLE `anesthmedsinventory` (
`AnestheticMedNum` bigint(20) NOT NULL auto_increment,
`AnesthMedName` char(30) default NULL,
`AnesthHowSupplied` char(20) default NULL,
`QtyOnHand` double default '0',
`DEASchedule` char(3) default NULL,
PRIMARY KEY (`AnestheticMedNum`)
) ENGINE=MyISAM DEFAULT CHARSET=utf8

By 'code that created the DataTable', do you mean the code from ClassConvertDatabase2.cs?

Thanks,
Cheers,

Bill Starck, DDS
Big Idea Software, LLC
Developer, EASy(Electronic Anesthesia System) for Open Dental
817-807-1709
TX, USA

User avatar
wjstarck
Posts: 936
Joined: Tue Jul 31, 2007 7:18 am
Location: Keller, TX
Contact:

Re: Crud DataTable code is bombing

Post by wjstarck » Sat May 22, 2010 12:41 pm

OK, NVM. I was able to find a workaround.

Thanks for taking time on a Saturday to help...
Cheers,

Bill Starck, DDS
Big Idea Software, LLC
Developer, EASy(Electronic Anesthesia System) for Open Dental
817-807-1709
TX, USA

User avatar
jordansparks
Site Admin
Posts: 5742
Joined: Sun Jun 17, 2007 3:59 pm
Location: Salem, Oregon
Contact:

Re: Crud DataTable code is bombing

Post by jordansparks » Sat May 22, 2010 12:49 pm

Well, if you're passing in a DataTable, it must have come from a query somewhere. I would need to see that code to see why that column was not part of that table.

Sorry I couldn't be more direct help. This sort of thing is complicated to do in a forum.
Jordan Sparks, DMD
http://www.opendental.com

User avatar
wjstarck
Posts: 936
Joined: Tue Jul 31, 2007 7:18 am
Location: Keller, TX
Contact:

Re: Crud DataTable code is bombing

Post by wjstarck » Sat May 22, 2010 2:20 pm

OK, I've got it now.

I was using a one of the GetOne methods similar to those found in any one Crud classes.

Turns out I was using a DataCore.NonQ(command) call when I should have been using a DataCore.GetScalar(command) call in another method. So the DataTable was being fed some null values, instead of the correct quantities. Hence the bomb.

Thanks again for your help...
Cheers,

Bill Starck, DDS
Big Idea Software, LLC
Developer, EASy(Electronic Anesthesia System) for Open Dental
817-807-1709
TX, USA

Post Reply