1 Replies - 2670 Views - Last Post: 20 November 2012 - 09:10 AM Rate Topic: -----

#1 wanabavbcoder  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 48
  • Joined: 08-October 12

displaying results from a stored procedure in a datalist

Posted 19 November 2012 - 09:25 AM

Hey people. Question is if i can display my results from a stored procedure in a datalist or something to that effect? I have a stored procedure but alot of searching on the net has not given me anything to go by. I am new to asp.net and c#. Im using .netframework 1.1 and there is no help. Any advice, or tuts or help???

using System;
using System.Data;
using System.Configuration;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.HtmlControls;
using System.Data.SqlClient;


namespace Logmein
{
	/// <summary>
	/// Summary description for Flightdetails.
	/// </summary>
	public class Flightdetails : System.Web.UI.Page
	{
		protected System.Web.UI.WebControls.DropDownList DropDownList1;
		protected System.Web.UI.WebControls.Label Label1;
		protected System.Web.UI.WebControls.Label Label2;
		protected System.Web.UI.WebControls.DropDownList DropDownList2;
		protected System.Web.UI.WebControls.Button Button1;
		protected System.Web.UI.WebControls.Label Label6;
		protected System.Web.UI.WebControls.DataGrid DataGrid1;
		protected System.Web.UI.WebControls.DataList DataList1;
		protected System.Web.UI.WebControls.Image Image5;
		
		private void Page_Load(object sender, System.EventArgs e)
		
		{
{

            SqlConnection conn = new SqlConnection("workstation id=RIKESH;packet size=4096;user id=sa;data source=RIKESH;persist security info=False;initial catalog=FlyWaySystem");

            SqlDataAdapter da = new SqlDataAdapter ("Select * FROM FlightInformation ", conn);

            DataSet ds = new DataSet();

            da.Fill (ds);

            DropDownList1.DataSource = ds;

            DropDownList1.DataValueField = "Origin";

            DropDownList1.DataBind () ;

            string selectedText1=DropDownList1.SelectedItem.Text;

            DropDownList2.DataSource = ds;

            DropDownList2.DataValueField = "Destination";

            DropDownList2.DataBind () ;

            string selectedText2=DropDownList2.SelectedItem.Text;

         

        }


			if (Session["update"]==null) 

			{ 

				Session["update"] = Server.UrlEncode(System.DateTime.Now.ToString()); 

			} 
		}

		#region Web Form Designer generated code
		override protected void OnInit(EventArgs e)
		{
			//
			// CODEGEN: This call is required by the ASP.NET Web Form Designer.
			//
			InitializeComponent();
			base.OnInit(e);
		}
		
		/// <summary>
		/// Required method for Designer support - do not modify
		/// the contents of this method with the code editor.
		/// </summary>
		private void InitializeComponent()
		{    
			this.Button1.Click += new System.EventHandler(this.Button1_Click);
			this.Load += new System.EventHandler(this.Page_Load);

		}
		#endregion

		private void Button1_Click(object sender, System.EventArgs e)
		{
			SqlConnection sqlconn; 

			SqlCommand sqlcomm; 

			sqlconn = new SqlConnection("workstation id=RIKESH;packet size=4096;user id=sa;data source=RIKESH;persist security info=False;initial catalog=FlyWaySystem"); 

			sqlconn.Open(); 

			sqlcomm = new SqlCommand(); 
				
			sqlcomm.Connection = sqlconn; 

			//Here I am definied command type is Stored Procedure. 

			sqlcomm.CommandType = CommandType.StoredProcedure; 

			//Here I mentioned the Stored Procedure Name. 

			sqlcomm.CommandText = "Searchflights"; 

			//Here I fix the variable values to Stored Procedure Parameters. You can easily understand if you can see the Stored Procedure Code. 
			sqlcomm.Parameters.Add("@origin", SqlDbType.NVarChar);  
			sqlcomm.Parameters["@origin"].Value = DropDownList1.SelectedItem.ToString();
			sqlcomm.Parameters.Add("@destination", SqlDbType.NVarChar);  
			sqlcomm.Parameters["@destination"].Value = DropDownList2.SelectedItem.ToString();
			sqlcomm.ExecuteNonQuery(); 
			SqlDataReader rdr = sqlcomm.ExecuteReader();
			//checking whether data reader contains any row.
			if (rdr.HasRows)
			{
				

			}
			sqlcomm.Dispose(); 
			sqlconn.Close(); 
		}
		
		
	}
}


http://cdn.dreaminco.../helpsmilie.gif

Is This A Good Question/Topic? 0
  • +

Replies To: displaying results from a stored procedure in a datalist

#2 rgfirefly24  Icon User is offline

  • D.I.C Lover
  • member icon


Reputation: 267
  • View blog
  • Posts: 1,477
  • Joined: 07-April 08

Re: displaying results from a stored procedure in a datalist

Posted 20 November 2012 - 09:10 AM

why on earth are you using .NET 1.1 when it is so far outdated that it isn't even supported anymore? you really should upgrade to at least 2.0 if not 4.0/4.5.

By upgrading away from .net 1.1 you can use DataTables which have a .Load function that will take in your reader object. For 1.1 it looks to be a bit more complicated.

//.NET 2.0 + example

DataTable table = new DataTable();

table.Load(reader);

DataList.DataSource = table;
DataList.DataBind();



This post has been edited by rgfirefly24: 20 November 2012 - 09:12 AM

Was This Post Helpful? 0
  • +
  • -

Page 1 of 1