Click here to Skip to main content
15,890,845 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
my code give me this error "Cannot bind to the property or column firstname on the DataSource.
Parameter name: dataMember"

my code here :

C#
da.SelectCommand = new SqlCommand("select * from student ",cs);
           ds.Clear();
           da.Fill(ds);
           dataGridView1.DataSource = ds.Tables[0];
         this.textBox1.DataBindings.Add("Text", this.tblnamesbs, "firstname",true);
         this.textBox2.DataBindings.Add("Text",this.tblnamesbs,"lastname",true);
Posted
Updated 4-Jan-14 9:20am
v2
Comments
Ron Beyer 4-Jan-14 15:20pm    
I believe data binding names are case sensitive, can you verify that your data binding column really is "firstname" and not something like "FirstName".
Karthik_Mahalingam 4-Jan-14 15:32pm    
yes Ron, this is the only issue that can occur for this error message., you can post this as answer....
mhassan083 4-Jan-14 15:48pm    
No,firstname is firstname and lastname is lastname not FIRSTNAME or LASTNAME or anything else
Karthik_Mahalingam 4-Jan-14 16:04pm    
try like this..

this.textBox1.DataBindings.Add(new Binding("Text", this.tblnamesbs, "firstname",true));
mhassan083 5-Jan-14 0:16am    
the same error message!

1 solution

firstname is not present in the datasource this.tblnamesbs.
add first name in the datasource or check the spelling of it . it will resolve ...

i tried this code,its working fine..

C#
DataTable tblnamesbs = new DataTable();

           tblnamesbs.Columns.Add("firstname", typeof(string));
           tblnamesbs.Rows.Add("one");

           BindingSource binding = new BindingSource();
           binding.DataSource = tblnamesbs;

           this.textBox1.DataBindings.Add("Text",binding,"firstname" );
 
Share this answer
 
v4
Comments
mhassan083 5-Jan-14 0:48am    
how can i use this in my code?
Karthik_Mahalingam 5-Jan-14 0:58am    
this is just sample..

pls check this.tblnamesbs object..

it is datatable or list?

apply break point and check the column firstname exists ?
if so , please check the case. or any space at end etc..
mhassan083 5-Jan-14 1:02am    
is BindingSource tblnamesbs =new BindingSource();
Karthik_Mahalingam 5-Jan-14 1:12am    
check my updated solution..
mhassan083 5-Jan-14 5:49am    
yes,good

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