Click here to Skip to main content
15,891,843 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
i have three table table teacher ,publication_app, and publication.
i have to use the id of teacher in publication_app then id of publication app into publication. and also i have to run the 4 quries at the same time.

C#
public void Addpublication(string Author, string designations ,string status_of_authoship, string faculty, string d,string id )
       {
           string q = "insert into Teacher (TName, Designation,Status_of_authorship, Department, dateAdded)values('" + Author + "', '" + designations + "','" + status_of_authoship + "','" + faculty + "','" + d + "')";
           cmd = new OleDbCommand(q, con);
           cmd.CommandText = q;
           cmd.Connection = con;
           con.Open();

         string   q2 =  "select Max(TID), from Teacher where Tname='Author' by DESC ORDER";
         cmd = new OleDbCommand(q2, con);
         cmd.CommandText = q2;
         cmd.Connection = con;


i have select id from one table and i dont know how to use it in another table plx tell me procedure using 4 quries on single click and usage of select value into another table
Posted
Comments
Richard MacCutchan 15-Sep-15 4:13am    
The first thing you need to do is learn how to use proper parameterised queries in SQL. Your code is wide open to SQL injection, hacking and loss of your data.

1 solution

You can write multiple SQL statements in one query so you can use the previous value of the same query to the next.
e.g.
C#
q ="DELCARE @teacherid int, @publicationid int; 
SET @teacherid  = SELECT id from teachertable;
SET @publicationid = SELECT id from publicationstable where teacherid = @teacherid;
INSERT INTO sometable (blah, blah) VALUES(@teacherid, @publicationid )";

execute query q and you are done. All in one statement
 
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