Click here to Skip to main content
15,892,809 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
onbutton click label will show next record from the accessdata base

i want to know - on buttonclick moving to next record and show it in label.
i will try but that only show 1st record or lastracord.

What I have tried:

using System.Data.OleDb;

namespace webfeedback
{
    public partial class _operator : System.Web.UI.Page
    {
        int i;
        int qn=1;
       protected void Page_Load(object sender, EventArgs e)
        {
            qn = i;
          
                OleDbConnection con = new OleDbConnection(@"Provider=Microsoft.ACE.OLEDB.12.0;Data Source=E:\applab\webfeedback\feedback.accdb");
                con.Open();
                string cs = "select * from operator_question";
                OleDbCommand cmd = new OleDbCommand(cs, con);
                OleDbDataReader reader = cmd.ExecuteReader();
                qn = i;
                int count = reader.FieldCount;
                while (qn < 20)
                {
                    if (reader.Read())
                    {
                        Label1.Text = reader["question_number"].ToString();
                        Label2.Text = reader["question"].ToString();
                    }
                }
        }
        protected void Button1_Click(object sender, EventArgs e)
        {
            
            i = qn++;
        }

    
    }
Posted
Updated 5-Jan-19 23:02pm

using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Data.SqlClient;
using System.Data;
using System.Configuration;
public partial class deleteproduct : System.Web.UI.Page
{
    SqlConnection con = new SqlConnection(@"data source=(local);initial catalog=Mob;integrated security=true");
    protected void Page_Load(object sender, EventArgs e)
    {
        Label1.Visible = false;
        Label2.Visible = false;
        Label3.Visible = false;
        Label4.Visible = false;
        Label5.Visible = false;
        Label6.Visible = false;
        Label7.Visible = false;
        Label8.Visible = false;
        Label9.Visible = false;
        Label10.Visible = false;
        Label11.Visible = false;
        Label12.Visible = false;
        Label13.Visible = false;
        Label14.Visible = false;
        Label15.Visible = false;
        Label16.Visible = false;
        Label17.Visible = false;
        Image1.Visible = false;
        Button1.Visible = false;
    }
    protected void DropDownList1_SelectedIndexChanged(object sender, EventArgs e)
    {
        con.Open();
        string query = "select ProductName,Model,Display,Camera,ProductImage,Sim,Price,OS,Description from Table_1 where ProductID='" + DropDownList1.Text + "'";
     SqlCommand    cmd = new SqlCommand(query, con);
        cmd.CommandType = CommandType.Text;
     IDataReader  dr = cmd.ExecuteReader();

        while (dr.Read())
        {
            Label6.Text = dr["ProductName"].ToString();
            Label7.Text = dr["Model"].ToString();
            Label8.Text = dr["Display"].ToString();
            Label9.Text = dr["Camera"].ToString();
           Image1.ImageUrl = dr["ProductImage"].ToString();
           Label14.Text = dr["Sim"].ToString();
           Label15.Text = dr["Price"].ToString();
           Label16.Text = dr["OS"].ToString();
           Label17.Text = dr["Description"].ToString();

        }

        dr.Close();
        Label1.Visible = true;
        Label2.Visible = true;
        Label3.Visible = true;
        Label4.Visible = true;
        Label5.Visible = true;
        Label6.Visible = true;
        Label7.Visible = true;
        Label8.Visible = true;
        Label9.Visible = true;
        Label10.Visible = true;
        Label11.Visible = true;
        Label12.Visible = true;
        Label13.Visible = true;
        Label14.Visible = true;
        Label15.Visible = true;
        Label16.Visible = true;
        Label17.Visible = true;
        Image1.Visible = true;
        Button1.Visible = true;
    }
}


By Arpit Upadhyay
 
Share this answer
 
Insert Image with Data in Data Base Useing Asp.net

using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Data.SqlClient;
public partial class addproduct : System.Web.UI.Page
{
    SqlConnection con = new SqlConnection(@"Data Source=(local);Initial Catalog=Mob;Integrated Security=True");
    protected void Page_Load(object sender, EventArgs e)
    {
        Label1.Visible = false;
    }
    protected void Button1_Click(object sender, EventArgs e)
    {
        if (FileUpload1.HasFile)
        {
            string strname = FileUpload1.FileName.ToString();
            FileUpload1.PostedFile.SaveAs(Server.MapPath("~/image/") + strname);
            con.Open();
            SqlCommand cmd = new SqlCommand("insert into Table_1 values('" + TextBox1.Text + "','" + TextBox2.Text + "','" + TextBox3.Text + "','" + TextBox4.Text + "','" + strname + "','" + DropDownList1.Text + "','" + TextBox6.Text + "','" + TextBox7.Text + "','" + TextBox8.Text + "')", con);
            cmd.ExecuteNonQuery();
            con.Close();
            Label1.Visible = true;
            Label1.Text = "Record Uploaded successfully!!!";
           
        }
        else
        {
            Label1.Visible = true;
            Label1.Text = "Plz upload the Record!!!!";
        }  
    }
}



By: Arpit Upadhyay
 
Share this answer
 
v4
I am not sure how the above code is working for you, it should have initiated an infinite loop in page load. However, an ideal solution would be to have a global dictionary type variable and save all of your database data, on button click just traverse through that. Also, it is not a good approach to keep the db connection open.
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900