By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
431,990 Members | 1,741 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 431,990 IT Pros & Developers. It's quick & easy.

GridView not displaying data even Reader object contains Rows

P: n/a
The property of GridView1.HasRows is true and after assigning
GridView.DataSource=reader, it does not display any records in the
GirdView.

I am i missing out something? Here is the code:
protected void Button1_Click(object sender, EventArgs e)
{
int AtmtransId=-1;
if (Session["CustomerId"]!=null)

AtmtransId=DataAccessLayer.ATMManager.getATMTransa ctionsID(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|\Banki ngDb.mdf;Integrated
Security=True;User Instance=True");
SqlCommand cmd = new SqlCommand(Query,sqlconnection);
cmd.Parameters.AddWithValue("@ATMTRANSID",Atmtrans Id);
sqlconnection.Open();
SqlDataReader reader=cmd.ExecuteReader();
sqlconnection.Close();
GridView1.DataSource=reader;
}

May 7 '07 #1
Share this Question
Share on Google+
1 Reply


P: n/a
Mel
When using the SQLDataReader the connection must be open to access the data
"weird0" <am********@gmail.comwrote in message
news:11*********************@y80g2000hsf.googlegro ups.com...
The property of GridView1.HasRows is true and after assigning
GridView.DataSource=reader, it does not display any records in the
GirdView.

I am i missing out something? Here is the code:
protected void Button1_Click(object sender, EventArgs e)
{
int AtmtransId=-1;
if (Session["CustomerId"]!=null)

AtmtransId=DataAccessLayer.ATMManager.getATMTransa ctionsID(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|\Banki ngDb.mdf;Integrated
Security=True;User Instance=True");
SqlCommand cmd = new SqlCommand(Query,sqlconnection);
cmd.Parameters.AddWithValue("@ATMTRANSID",Atmtrans Id);
sqlconnection.Open();
SqlDataReader reader=cmd.ExecuteReader();
sqlconnection.Close();
GridView1.DataSource=reader;
}

May 7 '07 #2

This discussion thread is closed

Replies have been disabled for this discussion.