Click here to Skip to main content
15,887,683 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
sir how o select id from one table and save in another table ........
my code....
C#
MySqlConnection exclecon = new MySqlConnection("Server=Localhost;DataBase=password1;user=root;password=nectar");
                   exclecon.Open();
                   MySqlCommand cmdYear = new MySqlCommand("INSERT INTO slayear (YEAR) VALUES(@YEAR)", exclecon);
                   cmdYear.Parameters.AddWithValue("@YEAR", YEAR);
                   MySqlCommand cmdMonth = new MySqlCommand("INSERT INTO slamonth (MONTH,contenttype) VALUES(@MONTH,@contenttype)=(select idyear from slayear where idyear=@idyear)  ", exclecon);
                   cmdMonth.Parameters.AddWithValue("@MONTH", MONTH);
                   cmdMonth.Parameters.Add("@contenttype", MySqlDbType.VarChar).Value = contenttype;

                   cmdYear.ExecuteNonQuery();
                   cmdMonth.ExecuteNonQuery();
[Edit]Code block added[/Edit]
Posted
Updated 18-May-13 6:06am
v2

1 solution

Hoping Year is unique in your slayear table, You can use another command to retrieve id for the same year you have inserted.

My suggestion is to try creating a storedprocedure which inserts year and returns the ID or updates your month details aswell.
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900