Hey there.

Now Reaaaaly close to finishing my project =), had a bit of scope creep with the person we are doing the project for. uffff, yea i know...

so now im saving all the details to my mysql database.

like this field. "name" of the person, i would save it like this

cmd.Parameters.AddWithValue("@First_Name", txtboxName.Text);

Butttt nowww.... i have a "student_level_ID" field in my Student table, which is a secondary key, related to "Level_id" in my Level table. so now if i want to save the data in the "level textbox" to the students secondary key, HOw would i do it?

Tables = Students and Student level
Fields = in Students = Student_level_ID
.........in Student level = Level_ID


for instance. Textbox Level --> "Advanced"
but now in my student table, i have to insert a 2 in the "student_level_ID" as that is the primary key in the "Level" table.

Ive tried a few ways, without much success.

Would be much appreciated if you could point me in the right direction once again.
thank you. =)

You don't provide enough information about the tables, but it would be something like:

UPDATE Students SET Student_Level = (SELECT Level_ID FROM Level WHERE Level_Name = @TextboxLevel) WHERE FirstName = @firstName AND LastName = @lastName

Some of the field I made up since I don't know what you call them in your database.

You don't provide enough information about the tables, but it would be something like:

UPDATE Students SET Student_Level = (SELECT Level_ID FROM Level WHERE Level_Name = @TextboxLevel) WHERE FirstName = @firstName AND LastName = @lastName

Some of the field I made up since I don't know what you call them in your database.

Oky kwl, thank you, that looked like it worked halfway with how i tried to change it. I found out how to do it. Dont know if its the correct way, but it worked a hundred percent.
I INNER JOIN'ed the primary key table, and the secondary key table, so with both of them in one table i could use or change them

So thank you very much =)

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.