How can i write sql query in C#.net

Posted by Mandlaa under ADO.NET on 12/23/2013 | Points: 10 | Views : 2396 | Status : [Member] | Replies : 8
C# Query

SqlDataAdapter da1 = new SqlDataAdapter("Select t.Tagusage,h.ProductName from Tagrankingtable t INNER JOIN TagTable h on t.TagId=h.TagId and(h.ClientId =)" + Session["ClientId"], con1);

This is my Sql query

Select t.Tagusage,h.ProductName from Tagrankingtable t INNER JOIN TagTable h on t.TagId=h.TagId and (h.ClientId =t.ClientId)

This sql query write in the c# code
How can i write in c#.net
Correct my C# query




Responses

Posted by: vishalneeraj-24503 on: 12/23/2013 [Member] [MVP] Platinum | Points: 25

Up
0
Down
SqlConnection con = new SqlConnection("conection string");

SqlDataAdapter da = new SqlDataAdapter("Select t.Tagusage,h.ProductName from Tagrankingtable t INNER JOIN TagTable h on t.TagId=h.TagId and h.ClientId ='" + Session["ClientId"] + "'", con);
DataSet ds = new DataSet();
da.Fill(ds);
return ds;


Mandlaa, if this helps please login to Mark As Answer. | Alert Moderator

Posted by: Mandlaa on: 12/23/2013 [Member] Starter | Points: 25

Up
0
Down


and h.ClientId = t.ClientId" instead of this i want to use session variable like(h.ClientId =)" + Session["ClientId"];

Mandlaa, if this helps please login to Mark As Answer. | Alert Moderator

Posted by: Bandi on: 12/23/2013 [Member] [MVP] Platinum | Points: 25

Up
0
Down
SqlDataAdapter da1 = new SqlDataAdapter("Select t.Tagusage,h.ProductName from Tagrankingtable t INNER JOIN TagTable h on t.TagId=h.TagId and(h.ClientId = " + Session["ClientId"] + ");",   con1); 


Mark This Response as Answer
--
Chandu
http://www.dotnetfunda.com/images/dnfmvp.gif

Mandlaa, if this helps please login to Mark As Answer. | Alert Moderator

Posted by: vishalneeraj-24503 on: 12/23/2013 [Member] [MVP] Platinum | Points: 25

Up
0
Down
Write this:-

"Select t.Tagusage,h.ProductName from Tagrankingtable t INNER JOIN TagTable h on t.TagId=h.TagId and h.ClientId ='" + Session["ClientId"] + "'"


Mandlaa, if this helps please login to Mark As Answer. | Alert Moderator

Posted by: Saranpselvam on: 1/2/2014 [Member] Starter | Points: 25

Up
0
Down
if the client id is "string format" then use the below

"Select t.Tagusage,h.ProductName from Tagrankingtable t INNER JOIN TagTable h on t.TagId=h.TagId and h.ClientId ='" + Session["ClientId"] + "'"

if the cliendid is integer


"Select t.Tagusage,h.ProductName from Tagrankingtable t INNER JOIN TagTable h on t.TagId=h.TagId and h.ClientId =" + Session["ClientId"]


Mandlaa, if this helps please login to Mark As Answer. | Alert Moderator

Posted by: Bageshkumarbagi on: 1/2/2014 [Member] Starter | Points: 25

Up
0
Down
SqlDataAdapter da = new SqlDataAdapter("Select t.Tagusage,h.ProductName from Tagrankingtable t INNER JOIN TagTable h on t.TagId=h.TagId and h.ClientId ='" + Session["ClientId"] + "'", con);

Thanks,
Bagesh Kumar Singh
Mark as answer if you have been satisfied

Mandlaa, if this helps please login to Mark As Answer. | Alert Moderator

Posted by: Bandi on: 1/3/2014 [Member] [MVP] Platinum | Points: 25

Up
0
Down
"Mark as Answer " if the above replies helped you

Mark This Response as Answer
--
Chandu
http://www.dotnetfunda.com/images/dnfmvp.gif

Mandlaa, if this helps please login to Mark As Answer. | Alert Moderator

Posted by: Snaveen on: 2/14/2014 [Member] Starter | Points: 25

Up
0
Down
SqlDataAdapter da1 = new SqlDataAdapter("Select t.Tagusage,h.ProductName from Tagrankingtable t INNER JOIN TagTable h on t.TagId=h.TagId and(h.ClientId =)" + Convert.ToInt32(Session["ClientId"]), con1); 


Check with above code...

Mandlaa, if this helps please login to Mark As Answer. | Alert Moderator

Login to post response