Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. Web Development
  3. ASP.NET
  4. quest

quest

Scheduled Pinned Locked Moved ASP.NET
database
3 Posts 3 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • J Offline
    J Offline
    jinovv
    wrote on last edited by
    #1

    hi am trying to do display the items from database to label.when i click the NEXT button ineed to display the second record to the label . how its posssible

    N T 2 Replies Last reply
    0
    • J jinovv

      hi am trying to do display the items from database to label.when i click the NEXT button ineed to display the second record to the label . how its posssible

      N Offline
      N Offline
      N a v a n e e t h
      wrote on last edited by
      #2

      Get the items in a datatable. Maintain a counter variable to count the previous and next clicks. According to the counter variable display values from datatable. Keep datatable in one session or cache.


      printf("Navaneeth!!") www.w3hearts.com

      1 Reply Last reply
      0
      • J jinovv

        hi am trying to do display the items from database to label.when i click the NEXT button ineed to display the second record to the label . how its posssible

        T Offline
        T Offline
        tonymathewt
        wrote on last edited by
        #3

        Suppose you have the required records in a datatable dt, you only need to iterate the row index keeping the column index constant. The rows index value needs to be stored into a hidden field after each iteration. Below is the C# code for the default.aspx for displaying the records. using System; using System.Data; using System.Web; using System.Web.UI; using System.Web.UI.WebControls; public partial class _Default : System.Web.UI.Page { Cls_DBtier Cls_DBtierobj = new Cls_DBtier(); int i = 0; DataTable dt; protected void Page_Load(object sender, EventArgs e) { Cls_DBtierobj.mvar_DBConnectionstring = Application["Connection_String"].ToString(); Cls_DBtierobj.OpenConnection(); dt = Cls_DBtierobj.getNames(); i = dt.Rows.Count; Cls_DBtierobj.CloseConnection(); LblNames.Text = dt.Rows[0][0].ToString(); } protected void BtnNxt_Click(object sender, EventArgs e) { int index = Convert.ToInt32(HidIndex.Value); if (index < i-1) { index = index + 1; HidIndex.Value = index.ToString(); LblNames.Text = dt.Rows[index][0].ToString(); } } } HidIndex is the hidden field, LblNames is the label for displaying the records. And BtnNxt is the button display the next record. Cls_DBtier is class file. Below is the code for it. using System; using System.Data; using System.Data.SqlClient; using System.Web; using System.Web.UI; using System.Web.UI.WebControls; using System.Web.UI.WebControls.WebParts; public class Cls_DBtier { public string mvar_DBConnectionstring; SqlConnection conn; public void OpenConnection() { conn = new SqlConnection(mvar_DBConnectionstring); } public void CloseConnection() { conn.Close(); } public SqlCommand ReturnSqlCommand(string sqlStmt) { SqlCommand Cmd; try { Cmd = new SqlCommand(); Cmd.Connection = conn; Cmd.CommandType = CommandType.Text; Cmd.CommandText = sqlStmt; return Cmd; } finally { Cmd = null; } } public DataTable getNames() { string stt = "SELECT ename FROM employee"; SqlDataAdapter SAdaptor; SqlCommand Cmd; DataSet ds=new DataSet(); DataTable dt; try { Cmd=ReturnSqlC

        1 Reply Last reply
        0
        Reply
        • Reply as topic
        Log in to reply
        • Oldest to Newest
        • Newest to Oldest
        • Most Votes


        • Login

        • Don't have an account? Register

        • Login or register to search.
        • First post
          Last post
        0
        • Categories
        • Recent
        • Tags
        • Popular
        • World
        • Users
        • Groups