Click here to Skip to main content
15,893,564 members
Please Sign up or sign in to vote.
4.00/5 (1 vote)
See more:
Something wrong is happening, when I'm trying to get the name of the table, which is currently shown in DataGridView. To get the table from Oracle, I use this code:
C#
DataSet ds = new DataSet();
OracleDataAdapter ndadptr = new OracleDataAdapter("SELECT * FROM"+               listBox1.SelectedItem.ToString(), OrConn.conn);
ndadptr.Fill(ds);
dataGridView1.DataSource = ds.Tables[0];

But when I'm trying to get current table name with
C#
dataGridView1.DataMember
it returns an empty string. For now, I've created class member Current_Table_Name, and write the selected item from listbox into it. Is there any other solution and how can I get the table name via DataMember property?
Posted

this way
C#
DataSet ds = new DataSet();
OracleDataAdapter ndadptr = new OracleDataAdapter("SELECT * FROM "+               listBox1.SelectedItem.ToString(), OrConn.conn);
ndadptr.Fill(ds);
dataGridView1.DataSource = ds.Tables[0];
dataGridView1.DataMember = ds.Tables[0].Name;


then you will able to retrieve datamember
Happy Coding!
:)
 
Share this answer
 
The answer at http://social.msdn.microsoft.com/forums/en-US/winformsdatacontrols/thread/592687b6-da67-4362-86c0-16c7e95de452/[^] explains why this is happening and also gives a workaround.
 
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