| | |
Retrieving data in asp.net using stored procedures
Please support our ASP advertiser: PostgreSQL or MySQL? Compare and contrast the two most popular open source databases
Thread Solved |
•
•
Join Date: Apr 2008
Posts: 11
Reputation:
Solved Threads: 0
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:
But nothing is getting displayed. Please help me. Thanx in advance
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)
Create Proc [dbo].[sptrainselect] @select int, @Route1 varchar(1000), @Route2 varchar(1000) as Begin If @select=1 Begin select Ident_Current('Train') as 'Identity' select * from Trains where Route like '%@Route1%' and Route like '%@Route2%' end end 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: SqlConnection cn = new SqlConnection("Data Source=SYS;Initial Catalog=Test;Integrated Security=True"); cn.Open(); SqlDataAdapter da = new SqlDataAdapter("sptrainselect", cn); da.SelectCommand.CommandType = CommandType.StoredProcedure; SqlParameter p1 = new SqlParameter("@Select", SqlDbType.Int); SqlParameter p2 = new SqlParameter("@Route1", SqlDbType.VarChar); SqlParameter p3 = new SqlParameter("@Route2", SqlDbType.VarChar); p1.Direction = ParameterDirection.Input; p2.Direction = ParameterDirection.Input; p3.Direction = ParameterDirection.Input; p1.Value = 1; p2.Value = txtfrom.Text; p3.Value = txtto.Text; da.SelectCommand.Parameters.Add(p1); da.SelectCommand.Parameters.Add(p2); da.SelectCommand.Parameters.Add(p3); DataSet ds = new DataSet(); da.Fill(ds, "Train"); dgtrains.DataSource = ds.Tables[1].DefaultView; dgtrains.DataBind(); cn.Close();
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.
Hi,
It seems your query is not returning any values.. try doing this
It seems your query is not returning any values.. try doing this
sql Syntax (Toggle Plain Text)
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... >>>
![]() |
Similar Threads
- LINQ Question (ASP.NET)
- Login and retrieve user data from database (ASP.NET)
Other Threads in the ASP Forum
- Previous Thread: Server side development
- Next Thread: file path problem
| Thread Tools | Search this Thread |
archive asp asp.net aspandmssqlserver2005 aspandmssqlserver2005connection aspconnection calendar changeable connection current database databaseconnection diagnostics dreamweaver excel fso html iis microsoft msmsql mssql2005 mssqlserver2005 mssqlserver2005andasp mssqlserverandasp opentextfile record searchbox selectoption server single specfic sqlserver sqlserverconnection toolkit web webserver windows7





