I am writing following code:
namespace WebApplication5
{
public partial class WebForm1 : System.Web.UI.Page
{
private DataSet dataset1 = new Data
Yes you are partially correct that your ds is Global but only for life time of Web Page. Once the page is rendered and sent to client, your page is disposed and hence with it the variable.
If you want to ds to be available in button_click event, either populate it inside Page_Load event
protected void Page_Load(object sender, EventArgs e)
{
OleDbConnection con = new OleDbConnection();
con.ConnectionString = @"Provider=Microsoft.ACE.OLEDB.12.0;Data Source=C:\Users\jayant\Documents\User_Details.accdb";
con.Open();
adapter = new OleDbDataAdapter("Select * from User_Details",con);
adapter.Fill(ds);
con.close();
}
Or generate the dataset in your Button_Click event handler.
If you do not want to generate this data set every time, you have to either keep this variable in Session or ViewState or Cache
UPDATE 1
The third and last option could be to make this dataset variable as class level variable i.e static and it would be available all the time