M
Max
Hi,
I have two database tables tblClasses and tblClassesWeb they are
identical only tblClassesWeb has two less columns. There are no
primary keys in the tables. What I am trying to accomplish is to
insert columns from tblClasses into tblClassesWeb in Visual Basic.NET
using SQL. I need to insert columns only if they don't already exist
in table I am inserting to (don't want to delete anything though). I
connect to db (code is omitted but it works) and execute the following
command:
sqlInsert = "INSERT INTO tblClassesWeb " & _
"(ExtSchoolID, ExtStudID, ExtTeacherID, SubjectTitle," &
_
" ExtClassID, SectionCode, PeriodCode) " & _
"SELECT" & _
" ExtSchoolID, ExtStudID, ExtTeacherID, SubjectTitle," &
_
" ExtClassID, SectionCode, PeriodCode " & _
"FROM tblClasses " & _
"WHERE tblClasses.ExtSchoolID <>
tblClassesWeb.ExtSchoolID " & _
"AND tblClasses.ExtStudID <> tblClassesWeb.ExtStudID
" & _
"AND tblClasses.ExtTeacherID <>
tblClassesWeb.ExtTeacherID " & _
"AND tblClasses.SubjectTitle <>
tblClassesWeb.SubjectTitle " & _
"AND tblClasses.ExtClassID <> tblClassesWeb.ClassID "
& _
"AND tblClasses.SectionCode <>
tblClassesWeb.SectionCode " & _
"AND tblClasses.PeriodCode <>
tblClassesWeb.PeriodCode"
the error I am getting after executing this command is "no value given
for one or more required parameters"
I stripped this string to the simplest case - inserting into 1 column
and using one where clause, I still get the same error.
I was also trying to accomplish this using WHERE NOT EXISTS clause
like this:
sqlInsert = "INSERT INTO tblClassesWeb SELECT ExtSchoolID, ExtStudID,
ExtTeacherID, SubjectTitle, ExtClassID, SectionCode, PeriodCode FROM
tblClasses WHERE Not Exists (SELECT * FROM tblClassesWeb)"
This works fine for the first time but if i add more entries to
tblClasses after the first run they won't get added to tblClassesWeb.
Can somebody please tell me how I can accomplish inserting rows from
one table to another using a conditional statements. Thank you
I have two database tables tblClasses and tblClassesWeb they are
identical only tblClassesWeb has two less columns. There are no
primary keys in the tables. What I am trying to accomplish is to
insert columns from tblClasses into tblClassesWeb in Visual Basic.NET
using SQL. I need to insert columns only if they don't already exist
in table I am inserting to (don't want to delete anything though). I
connect to db (code is omitted but it works) and execute the following
command:
sqlInsert = "INSERT INTO tblClassesWeb " & _
"(ExtSchoolID, ExtStudID, ExtTeacherID, SubjectTitle," &
_
" ExtClassID, SectionCode, PeriodCode) " & _
"SELECT" & _
" ExtSchoolID, ExtStudID, ExtTeacherID, SubjectTitle," &
_
" ExtClassID, SectionCode, PeriodCode " & _
"FROM tblClasses " & _
"WHERE tblClasses.ExtSchoolID <>
tblClassesWeb.ExtSchoolID " & _
"AND tblClasses.ExtStudID <> tblClassesWeb.ExtStudID
" & _
"AND tblClasses.ExtTeacherID <>
tblClassesWeb.ExtTeacherID " & _
"AND tblClasses.SubjectTitle <>
tblClassesWeb.SubjectTitle " & _
"AND tblClasses.ExtClassID <> tblClassesWeb.ClassID "
& _
"AND tblClasses.SectionCode <>
tblClassesWeb.SectionCode " & _
"AND tblClasses.PeriodCode <>
tblClassesWeb.PeriodCode"
the error I am getting after executing this command is "no value given
for one or more required parameters"
I stripped this string to the simplest case - inserting into 1 column
and using one where clause, I still get the same error.
I was also trying to accomplish this using WHERE NOT EXISTS clause
like this:
sqlInsert = "INSERT INTO tblClassesWeb SELECT ExtSchoolID, ExtStudID,
ExtTeacherID, SubjectTitle, ExtClassID, SectionCode, PeriodCode FROM
tblClasses WHERE Not Exists (SELECT * FROM tblClassesWeb)"
This works fine for the first time but if i add more entries to
tblClasses after the first run they won't get added to tblClassesWeb.
Can somebody please tell me how I can accomplish inserting rows from
one table to another using a conditional statements. Thank you