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)
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();
But nothing is getting displayed. Please help me. Thanx in advance