I facing some problem in SQL query.I try to use select result in other select query to get the result but its not working. Can anyone guide me. Below is the code i use in WCF.Thank u very much.
SqlCommand command = new SqlCommand("select tName from dbo.tblBankBranch where nBankID=(select nID from dbo.tblBankBranch where tState='" + tBank + "')", con);
SqlDataReader reader = command.ExecuteReader();
I’m guessing that you actually get an error that is caught and ignored somewhere. The SQL statement looks fishy.
It will only work if there is a single branch in the state, otherwise you will get an error.
Try writing it as a JOIN. Ignore that, why have tblBankBranch in there twice?
If the fields nBankID and nID are really different in the single table, and you do want to link them in that way, then the JOIN form is
I’ll leave it to you to flatten the statements for use in C#.