943,713 Members | Top Members by Rank

Ad:
  • ASP Discussion Thread
  • Marked Solved
  • Views: 2823
  • ASP RSS
Mar 27th, 2009
0

Retrieving data in asp.net using stored procedures

Expand Post »
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:
ASP Syntax (Toggle Plain Text)
  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.
Similar Threads
Reputation Points: 10
Solved Threads: 0
Newbie Poster
happyns is offline Offline
18 posts
since Apr 2008
Apr 2nd, 2009
0

Re: Retrieving data in asp.net using stored procedures

Hi,

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

sql Syntax (Toggle Plain Text)
  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]
Reputation Points: 10
Solved Threads: 6
Light Poster
vizy is offline Offline
36 posts
since Dec 2007
Apr 2nd, 2009
0

Re: Retrieving data in asp.net using stored procedures

@vizy,
Thank you very much dude. I got the rite output. Once again i thank you very very very much
Reputation Points: 10
Solved Threads: 0
Newbie Poster
happyns is offline Offline
18 posts
since Apr 2008
Apr 5th, 2009
0

Re: Retrieving data in asp.net using stored procedures

ok.. good
You are welcome..

please mark this thread as solved..
Reputation Points: 10
Solved Threads: 6
Light Poster
vizy is offline Offline
36 posts
since Dec 2007

This thread is solved

Either the thread starter or a moderator has marked this thread as solved. You can most likely trust the responses and answers given. There is most likely no reason for any further responses to be posted here. If you have a related question, please start a new thread in this forum instead.

This thread is more than three months old

No one has posted to this discussion for at least three months. Please let old threads die and do not reply to them unless you feel you have something new and valuable to contribute that absolutely must be added to make the discussion complete. Otherwise, please start a new thread in this forum instead.
Message:
Previous Thread in ASP Forum Timeline: Server side development
Next Thread in ASP Forum Timeline: file path problem





About Us | Contact Us | Advertise | Acceptable Use Policy
Forum Index | Build Custom RSS Feed


Follow us on Twitter


© 2011 DaniWeb® LLC