W
weird0
I have created a GridView and dynamically added data to it by
creating a DataTable(as advised) and bound it with a reader. Then,
assigned the DataSource of GridView to DataTable. But even that aint
working as alternatively
assigned reader obj. to datasource of GridView. Here is the code for
the aspx.cs page: ( The reader surely cootains data as its HasRows
property is true). Plz help. Never got stuck this bad with a problem.
For more than two weeks.
protected void Button1_Click(object sender, EventArgs e)
{
// CustID->AccId->ATM-Id->Atm_TransID....
int AtmtransId=-1;
if (Session["CustomerId"]!=null)
AtmtransId=DataAccessLayer.ATMManager.getATMTransactionsID(Session["CustomerId"].ToString(),AccNamesList.SelectedItem.Text);
string Query = "SELECT atmtrans_date AS Date,atmtrans_branch
AS Branch,atmtrans_type AS Type,atmtrans_amount AS Amount FROM
ATM_Transactions WHERE atmtrans_id=@ATMTRANSID";
SqlConnection sqlconnection = new SqlConnection(@"Data Source=.
\SQLEXPRESS;AttachDbFilename=|DataDirectory|\BankingDb.mdf;Integrated
Security=True;User Instance=True");
SqlCommand cmd = new SqlCommand(Query,sqlconnection);
cmd.Parameters.AddWithValue("@ATMTRANSID",AtmtransId);
GridView GridView1 = new GridView();
sqlconnection.Open();
// Fill the Data Reader
SqlDataReader reader=cmd.ExecuteReader();
//Create a DataTable object
DataTable dt=new DataTable();
//Load Data from Data Reader to DataTable object
dt.Load(reader);
//Fill the GridView Control
GridView1.DataSource = dt;
GridView1.DataBind();
reader.Close();
sqlconnection.Close();
}
creating a DataTable(as advised) and bound it with a reader. Then,
assigned the DataSource of GridView to DataTable. But even that aint
working as alternatively
assigned reader obj. to datasource of GridView. Here is the code for
the aspx.cs page: ( The reader surely cootains data as its HasRows
property is true). Plz help. Never got stuck this bad with a problem.
For more than two weeks.
protected void Button1_Click(object sender, EventArgs e)
{
// CustID->AccId->ATM-Id->Atm_TransID....
int AtmtransId=-1;
if (Session["CustomerId"]!=null)
AtmtransId=DataAccessLayer.ATMManager.getATMTransactionsID(Session["CustomerId"].ToString(),AccNamesList.SelectedItem.Text);
string Query = "SELECT atmtrans_date AS Date,atmtrans_branch
AS Branch,atmtrans_type AS Type,atmtrans_amount AS Amount FROM
ATM_Transactions WHERE atmtrans_id=@ATMTRANSID";
SqlConnection sqlconnection = new SqlConnection(@"Data Source=.
\SQLEXPRESS;AttachDbFilename=|DataDirectory|\BankingDb.mdf;Integrated
Security=True;User Instance=True");
SqlCommand cmd = new SqlCommand(Query,sqlconnection);
cmd.Parameters.AddWithValue("@ATMTRANSID",AtmtransId);
GridView GridView1 = new GridView();
sqlconnection.Open();
// Fill the Data Reader
SqlDataReader reader=cmd.ExecuteReader();
//Create a DataTable object
DataTable dt=new DataTable();
//Load Data from Data Reader to DataTable object
dt.Load(reader);
//Fill the GridView Control
GridView1.DataSource = dt;
GridView1.DataBind();
reader.Close();
sqlconnection.Close();
}