Click here to Skip to main content
15,395,652 members
Home / Discussions / C#
   

C#

 
AnswerRe: Loading a type dynamically Pin
Eddy Vluggen2-Jul-16 0:50
professionalEddy Vluggen2-Jul-16 0:50 
AnswerRe: Loading a type dynamically Pin
BillWoodruff3-Jul-16 1:58
mveBillWoodruff3-Jul-16 1:58 
GeneralRe: Loading a type dynamically Pin
Super Lloyd3-Jul-16 2:25
MemberSuper Lloyd3-Jul-16 2:25 
QuestionSplit Excel Workbook to sheets Pin
Magic19041-Jul-16 9:05
MemberMagic19041-Jul-16 9:05 
AnswerRe: Split Excel Workbook to sheets Pin
Gerry Schmitz1-Jul-16 9:39
mveGerry Schmitz1-Jul-16 9:39 
AnswerRe: Split Excel Workbook to sheets Pin
Richard MacCutchan1-Jul-16 21:22
mveRichard MacCutchan1-Jul-16 21:22 
AnswerRe: Split Excel Workbook to sheets Pin
Patrice T2-Jul-16 17:26
mvePatrice T2-Jul-16 17:26 
QuestionLinq to SQL multiple tables problem Pin
Member 119277061-Jul-16 8:23
MemberMember 119277061-Jul-16 8:23 
C#
public class AMCOMDB : DataContext
        {
            public Table<student> allStudents;
            public Table<aClass> allClasses;
            public AMCOMDB(string connection) : base(connection) { } 
        }

C#
[Table(Name = "student")]
        public class student
        {
            
            private string _studentName;
            [Column(IsPrimaryKey =true,Storage ="_studentName")]
            public string studentName
            {
                get
                {
                    return this._studentName;
                }
                set
                {
                    this._studentName = value;
                }
            }
            private string _LARType;
            [Column(Storage ="_LARType")]
            public string LARType
            {
                get
                {
                    return this._LARType;
                }
                set
                {
                    this._LARType = value;
                }
            }
            private string _studentType;
            [Column(Storage = "_studentType")]
            public string studentType
            {
                get
                {
                    return this._studentType;
                }
                set
                {
                    this._studentType = value;
                }
            }
            private string _aviationLevel;
            [Column(Storage = "_aviationLevel")]
            public string aviationLevel
            {
                get
                {
                    return this._aviationLevel;
                }
                set
                {
                    this._aviationLevel = value;
                }
            }
            private string _airDefenseLevel;
            [Column(Storage = "_airDefenseLevel")]
            public string airDefenseLevel
            {
                get
                {
                    return this._airDefenseLevel;
                }
                set
                {
                    this._airDefenseLevel = value;
                }
            }
            private string _emergencyContact;
            [Column(Storage = "_emergencyContact")]
            public string emergencyContact
            {
                get
                {
                    return this._emergencyContact;
                }
                set
                {
                    this._emergencyContact = value;
                }
            }

C#
[Table(Name = "grades")]
        public class grades
        {
            private string _studentName;
            [Column(IsPrimaryKey = true, Storage = "_studentName")]
            public string studentName
            {
                get
                {
                    return this._studentName;
                }
                set
                {
                    this._studentName = value;
                }
            }
            private int _ET;
            [Column(Storage = "_ET")]
            public int ET
            {
                get
                {
                    return this._ET;
                }
                set
                {
                    this._ET = value;
                }
            }
            private int _CP;
            [Column(Storage = "_CP")]
            public int CP
            {
                get
                {
                    return this._CP;
                }
                set
                {
                    this._CP = value;
                }
            }
            private int _SB;
            [Column(Storage = "_SB")]
            public int SB
            {
                get
                {
                    return this._SB;
                }
                set
                {
                    this._SB = value;
                }
            }
            private int _EC;
            [Column(Storage = "_EC")]
            public int EC
            {
                get
                {
                    return this._EC;
                }
                set
                {
                    this._EC = value;
                }
            }
            private int _finalGrade;
            [Column(Storage = "_finalGrade")]
            public int finalGrade
            {
                get
                {
                    return this._finalGrade;
                }
                set
                {
                    this._finalGrade = value;
                }
            }

C#
[Table(Name = "classes")]
        public class aClass
        {
            private string _classNumber;
            [Column(IsPrimaryKey = true, Storage = "_classNumber")]
            public string classNumber
            {
                get
                {
                    return this._classNumber;
                }
                set
                {
                    this._classNumber = value;
                }
            }
            private string _courseSeries;
            [Column(Storage = "_courseSeries")]
            public string courseSeries
            {
                get
                {
                    return this._courseSeries;
                }
                set
                {
                    this._courseSeries = value;
                }
            }
            private string _courseNumber;
            [Column(Storage = "_courseNumber")]
            public string courseNumber
            {
                get
                {
                    return this._courseNumber;
                }
                set
                {
                    this._courseNumber = value;
                }
            }
            private string _distanceLearning;
            [Column(Storage = "_distanceLearning")]
            public string distanceLearning
            {
                get
                {
                    return this._distanceLearning;
                }
                set
                {
                    this._distanceLearning = value;
                }
            }
            private string _classStartDate;
            [Column(Storage = "_classStartDate")]
            public string classStartDate
            {
                get
                {
                    return this._classStartDate;
                }
                set
                {
                    this._classStartDate = value;
                }
            }
            private string _classEndDate;
            [Column(Storage = "_classEndDate")]
            public string classEndDate
            {
                get
                {
                    return this._classEndDate;
                }
                set
                {
                    this._classEndDate = value;
                }
            }
            private string _primaryInstructor;
            [Column(Storage = "_primaryInstructor")]
            public string primaryInstructor
            {
                get
                {
                    return this._primaryInstructor;
                }
                set
                {
                    this._primaryInstructor = value;
                }
            }
            private string _secondaryInstructor;
            [Column(Storage = "_secondaryInstructor")]
            public string secondaryInstructor
            {
                get
                {
                    return this._secondaryInstructor;
                }
                set
                {
                    this._secondaryInstructor = value;
                }
            }
            private string _location;
            [Column(Storage = "_location")]
            public string location
            {
                get
                {
                    return this._location;
                }
                set
                {
                    this._location = value;
                }
            }
            private string _TDYCosts;
            [Column(Storage = "_TDYCosts")]
            public string TDYCosts
            {
                get
                {
                    return this._TDYCosts;
                }
                set
                {
                    this._TDYCosts = value;
                }
            }
            private string _studentCount;
            [Column(Storage = "_studentCount")]
            public string studentCount
            {
                get
                {
                    return this._studentCount;
                }
                set
                {
                    this._studentCount = value;
                }
            }
            private List<grades> _classGrades;
            [Column(Storage = "_classGrades")]
            public List<grades> classGrades
            {
                get
                {
                    return this._classGrades;
                }
                set
                {
                    this._classGrades = value;
                }
            }

As you can see I have 3 classes under 1 database file. The problem I am having is that when I try to pull data using:

C#
AMCOMDB ADB = new AMCOMDB(connectionString);
            if (ADB.DatabaseExists())
            {

                var stud = ADB.GetTable<student>();
                var clas = ADB.GetTable<aClass>();
                IQueryable<string> query = from c in stud
                                           where c.studentName.Length > 5
                                           orderby c.studentName.Length
                                           select c.studentName.ToUpper();
                foreach (string name in query)
                {

                }
                //var q = from a in ADB.GetTable<student>()
                //       select a;
                //dtStudents = LinqQuerytoDataTable(q);
                //var q1 = from a in ADB.GetTable<aClass>()
                //         select a;
                //aClass c = new aClass();

                //dtClasses = reformatDataTable(q1);
            }

I get this at the foreach statement:

An unhandled exception of type 'System.Data.SqlClient.SqlException' occurred in System.Data.dll

Additional information: Invalid object name 'student'.

I have tried to change everything and I even tried to create 3 database files but the error still comes up. I don't know what I am doing wrong. Any help is appreciated.

modified 1-Jul-16 15:28pm.

AnswerRe: Linq to SQL multiple tables problem Pin
Gerry Schmitz1-Jul-16 9:52
mveGerry Schmitz1-Jul-16 9:52 
QuestionHow to render empty byte array element as xml tag in c#? Pin
Raghavendra.Kodimala1-Jul-16 4:42
professionalRaghavendra.Kodimala1-Jul-16 4:42 
AnswerRe: How to render empty byte array element as xml tag in c#? Pin
Gerry Schmitz1-Jul-16 5:26
mveGerry Schmitz1-Jul-16 5:26 
GeneralRe: How to render empty byte array element as xml tag in c#? Pin
Raghavendra.Kodimala1-Jul-16 6:40
professionalRaghavendra.Kodimala1-Jul-16 6:40 
GeneralRe: How to render empty byte array element as xml tag in c#? Pin
Gerry Schmitz1-Jul-16 9:33
mveGerry Schmitz1-Jul-16 9:33 
QuestionLock the Computer Pin
A-M-S-S1-Jul-16 3:47
MemberA-M-S-S1-Jul-16 3:47 
AnswerRe: Lock the Computer Pin
Pete O'Hanlon1-Jul-16 4:23
mvaPete O'Hanlon1-Jul-16 4:23 
GeneralRe: Lock the Computer Pin
Richard MacCutchan1-Jul-16 7:26
mveRichard MacCutchan1-Jul-16 7:26 
GeneralRe: Lock the Computer Pin
Pete O'Hanlon1-Jul-16 8:04
mvaPete O'Hanlon1-Jul-16 8:04 
JokeRe: Lock the Computer Pin
Peter_in_27801-Jul-16 12:38
professionalPeter_in_27801-Jul-16 12:38 
GeneralRe: Lock the Computer Pin
A-M-S-S3-Jul-16 5:17
MemberA-M-S-S3-Jul-16 5:17 
QuestionRe: Lock the Computer Pin
Eddy Vluggen3-Jul-16 8:48
professionalEddy Vluggen3-Jul-16 8:48 
AnswerRe: Lock the Computer Pin
A-M-S-S5-Jul-16 0:36
MemberA-M-S-S5-Jul-16 0:36 
AnswerRe: Lock the Computer Pin
Eddy Vluggen1-Jul-16 4:39
professionalEddy Vluggen1-Jul-16 4:39 
GeneralRe: Lock the Computer Pin
A-M-S-S5-Jul-16 0:44
MemberA-M-S-S5-Jul-16 0:44 
GeneralRe: Lock the Computer Pin
Eddy Vluggen5-Jul-16 0:51
professionalEddy Vluggen5-Jul-16 0:51 
QuestionHow to reach a file under a folder inside a solution in VS C# Pin
jasonalien30-Jun-16 21:57
Memberjasonalien30-Jun-16 21:57 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.