Rick Doll

Rick Doll

  • NA
  • 47
  • 0

reading 1 piece of info from a selected index.

Aug 28 2008 10:51 PM

As the title states I want to read the one pice of info from a collumn on the selected row.

I am sure it is easy...I just haven't figured that part yet.

The following code is where I am so far. I posted this at msdn forums last night but no responses yet so am hoping someone knows here.

protected void GridView1_SelectedIndexChanged(object sender, EventArgs e)


using (OleDbConnection con = new OleDbConnection())


con.ConnectionString = ConfigurationManager.ConnectionStrings["MNLlasteditConnectionString"].ConnectionString;


OleDbCommand command = new OleDbCommand("select LastName from Players;", con);

OleDbDataReader reader = command.ExecuteReader();

string info = "";

while (reader.Read())


info = reader.GetString(0);

TextBox1.Text = info.ToString();



}//closes using.

}//closes  method.


I want to have it display the name of the player that is in the selected row. i have the grid view narrowed down to just some players in the team called "Draft" but i assume this is reading a player from the entire databse.


I added this to my command

Where Team = 'Draft'


to make the new command

OleDbCommand command = new OleDbCommand("select LastName from Players Where Team = 'Draft';", con)


It found a player in the draft tag fine but I am not even sure what reason its using for that player. it grabs the same one every time and he is not the first or the last player in that section so its like it said this is who we want randomly and just decided it will be the same everytime.


How can I make it grab the row its in and the last name of that player?


Thank you in advance to any who know the next step.

Answers (1)