Hello,
I have 2 problems that I can't seem to understand,maybe you can help me.The first one is not described in the question but it concerns directly the database and my inner join.Before I tried to insert values into the table RegisterTeacher,everything was working fine,specifically this method that retrieves the rows from "education" column.
public IEnumerable<Cours> GetByEducation()
{
using (var context = new DatabaseStudentsEntities1())
{
var query = (from data in context.Courses select new { Education = data.education }).ToList().Select(c => new Cours { education = c.Education }).ToList();
return query.ToList();
}
}
After I tried to insert the values from the registration into the database,i get this error(although I have checked all the values in the tables along with foreign keys and primary keys):"
Additional information: Schema specified is not valid. Errors:
The relationship 'DatabaseStudentsModel.FK_Login_ToTable' was not loaded because the type 'DatabaseStudentsModel.RegisterTeacher' is not available."
Why???It did that before a couple of times but it allowed me to actually go on the register page and input data.Now it won't let me do that,and I don't understand why.Second,I have my inner join which I don't know how to do it exactly.Can anyone pleasegive me an example of inner join in C# for inserting data in 2 tables?These are my tables:
CREATE TABLE [dbo].[Courses] (
[courseID] INT NOT NULL,
[courseName] NVARCHAR (MAX) NOT NULL,
[education] NVARCHAR (50) NULL,
PRIMARY KEY CLUSTERED ([courseID] ASC)
);
CREATE TABLE [dbo].[RegisterTeacher] (
[SNTeacher] INT NOT NULL,
[UserName] NVARCHAR (10) NOT NULL,
[pwd] INT NOT NULL,
[fullName] NVARCHAR (MAX) NOT NULL,
[CourseName] NVARCHAR (MAX) NOT NULL,
PRIMARY KEY CLUSTERED ([SNTeacher] ASC)
);
I would like to inner join the column education...
What I have tried:
I have tried this sintax for inner join:
SqlConnection conn = new SqlConnection(@"Data Source=(LocalDB)\MSSQLLocalDB;AttachDbFilename=C:\Users\User\source\repos\VIAApp2Demo\VIAApp2Demo\DB\DatabaseStudents.mdf;Integrated Security=True;Connect Timeout=30");
try
{
if (conn.State == System.Data.ConnectionState.Closed)
conn.Open();
String query = "INSERT INTO RegisterTeacher( SNTeacher,UserName,pwd,fullName,CourseName) INNER JOIN education on Courses.education=RegisterTeacher.education VALUES(@SNTeacher,@UserName,@pwd,@fullName,@CourseName,@education)";
SqlCommand cmd = new SqlCommand(query, conn);
cmd.CommandType = CommandType.Text;
Am I on the right track?