Retrieving data in asp.net using stored procedures

Thread Solved

Join Date: Apr 2008
Posts: 10
Reputation: happyns is an unknown quantity at this point 
Solved Threads: 0
happyns happyns is offline Offline
Newbie Poster

Retrieving data in asp.net using stored procedures

 
0
  #1
Mar 27th, 2009
Hello everyone Im doing a dummy project in asp.net. I have a table named trains with following fields:
1. Sno(Primary key, Identity Increment, integer)
2. Train_no(varchar(100))
3. Train_name(varchar(200))
4. Route(varchar(1000))
5. Start(varchar(100))
6. End(varchar(100))

For this i have created a stored Procedure in this way:
  1. Create Proc [dbo].[sptrainselect]
  2. @select int,
  3. @Route1 varchar(1000),
  4. @Route2 varchar(1000)
  5. as
  6. Begin
  7. If @select=1
  8. Begin
  9. select Ident_Current('Train') as 'Identity'
  10. select * from Trains where Route like '%@Route1%' and Route like '%@Route2%'
  11. end
  12. end
  13. In asp.net after clicking a linkbutton the grid named dgtrains has to display taking Route1 and Route2 Parameters from 2 textboxes. For that linkbutton click i wrote the code as follows:
  14. SqlConnection cn = new SqlConnection("Data Source=SYS;Initial Catalog=Test;Integrated Security=True");
  15. cn.Open();
  16. SqlDataAdapter da = new SqlDataAdapter("sptrainselect", cn);
  17. da.SelectCommand.CommandType = CommandType.StoredProcedure;
  18. SqlParameter p1 = new SqlParameter("@Select", SqlDbType.Int);
  19. SqlParameter p2 = new SqlParameter("@Route1", SqlDbType.VarChar);
  20. SqlParameter p3 = new SqlParameter("@Route2", SqlDbType.VarChar);
  21. p1.Direction = ParameterDirection.Input;
  22. p2.Direction = ParameterDirection.Input;
  23. p3.Direction = ParameterDirection.Input;
  24. p1.Value = 1;
  25. p2.Value = txtfrom.Text;
  26. p3.Value = txtto.Text;
  27. da.SelectCommand.Parameters.Add(p1);
  28. da.SelectCommand.Parameters.Add(p2);
  29. da.SelectCommand.Parameters.Add(p3);
  30. DataSet ds = new DataSet();
  31. da.Fill(ds, "Train");
  32. dgtrains.DataSource = ds.Tables[1].DefaultView;
  33. dgtrains.DataBind();
  34. cn.Close();
But nothing is getting displayed. Please help me. Thanx in advance
Last edited by peter_budo; Mar 27th, 2009 at 3:31 pm. Reason: Keep It Organized - For easy readability, always wrap programming code within posts in [code] (code blocks) and [icode] (inline code) tags.
Reply With Quote Quick reply to this message  
Join Date: Dec 2007
Posts: 34
Reputation: vizy is an unknown quantity at this point 
Solved Threads: 6
vizy's Avatar
vizy vizy is offline Offline
Light Poster

Re: Retrieving data in asp.net using stored procedures

 
0
  #2
Apr 2nd, 2009
Hi,

It seems your query is not returning any values.. try doing this

  1. SELECT * FROM Trains WHERE Route LIKE '%'+@Route1+'%' AND Route LIKE '%'+@Route2+'%'
Last edited by peter_budo; Apr 5th, 2009 at 4:58 am. Reason: Please stop using [quote] tag and use [code]
Njoy koding... >>>
Reply With Quote Quick reply to this message  
Join Date: Apr 2008
Posts: 10
Reputation: happyns is an unknown quantity at this point 
Solved Threads: 0
happyns happyns is offline Offline
Newbie Poster

Re: Retrieving data in asp.net using stored procedures

 
0
  #3
Apr 2nd, 2009
@vizy,
Thank you very much dude. I got the rite output. Once again i thank you very very very much
Reply With Quote Quick reply to this message  
Join Date: Dec 2007
Posts: 34
Reputation: vizy is an unknown quantity at this point 
Solved Threads: 6
vizy's Avatar
vizy vizy is offline Offline
Light Poster

Re: Retrieving data in asp.net using stored procedures

 
0
  #4
Apr 5th, 2009
ok.. good
You are welcome..

please mark this thread as solved..
Njoy koding... >>>
Reply With Quote Quick reply to this message  
Reply

This thread has been marked solved.
Perhaps start a new thread instead?
Message:



Similar Threads
Other Threads in the ASP Forum
Thread Tools Search this Thread



About Us | Contact Us | Advertise | DaniWeb | Acceptable Use Policy | RSS Feed

©2003 - 2009 DaniWeb® LLC