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:

Create Proc [dbo].[sptrainselect]
@select int,
@Route1 varchar(1000),
@Route2 varchar(1000)
If @select=1
select Ident_Current('Train') as 'Identity'
select * from Trains where Route like '%@Route1%' and Route like '%@Route2%'
 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");
        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;
        DataSet ds = new DataSet();
        da.Fill(ds, "Train");
        dgtrains.DataSource = ds.Tables[1].DefaultView;

But nothing is getting displayed. Please help me. Thanx in advance

Recommended Answers

All 3 Replies


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

select * from Trains where Route like '%'+@Route1+'%' and Route like '%'+@Route2+'%'

Thank you very much dude. I got the rite output. Once again i thank you very very very much

ok.. good
You are welcome..

please mark this thread as solved..

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, learning, and sharing knowledge.