Click here to Skip to main content
15,902,886 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I need to bind fields of datatable to textboxes in winfrom here's the code i'm using:

C#
string currenciesQuery = "SELECT * FROM Currencies";
           currencyDataSet1 = new DataSets.CurrencyDataSet();
           DataTable dataTable = currencyDataSet1.Tables.Add("Currencies");
           string connectionString = System.Configuration.ConfigurationSettings.AppSettings["SQLConnectionString"].ToString();

           using (SqlConnection connection = new SqlConnection(connectionString))
           {
               SqlDataAdapter dataAdapter = new SqlDataAdapter(currenciesQuery, connection);

               dataAdapter.Fill(currencyDataSet1, "Currencies");
           }

           txtId.DataBindings.Add("Int", dataTable, "CurrencyId");
           txtCode.DataBindings.Add("Text", dataTable, "CurrencyCode");
           txtName.DataBindings.Add("Text", dataTable, "CurrencyName");
           txtRate.DataBindings.Add("Decimal", dataTable, "CurrencyRate");


It's generating an exception:

"Cannot bind to the property 'Int' on the target control.
Parameter name: PropertyName"
Posted
Updated 13-Dec-16 22:25pm

Two mistakes:

C#
//txtId.DataBindings.Add("Int", dataTable, "CurrencyId");
txtId.DataBindings.Add("Text", dataTable, "CurrencyId");
//txtRate.DataBindings.Add("Decimal", dataTable, "CurrencyRate");
txtRate.DataBindings.Add("Text", dataTable, "CurrencyRate");
 
Share this answer
 
Comments
AR1988 23-Nov-13 15:18pm    
Cannot bind to the property or column CurrencyCode on the DataSource.
Parameter name: dataMember
Peter Leow 23-Nov-13 16:05pm    
Let's solved one thing at a time. Was the first exception '"Cannot bind to the property 'Int' on the target control. Parameter name: PropertyName" solved by my first solution?

The second exception is saying that there is no 'CurrencyCode' on the DataSource, please check that it exists in the Currencies table, or is it typo?
satheeshk787 21-Sep-14 10:51am    
Thanks.....
//txtId.DataBindings.Add("Int", dataTable, "CurrencyId");
txtId.DataBindings.Add("Text", dataTable, "CurrencyId");
//txtRate.DataBindings.Add("Decimal", dataTable, "CurrencyRate");
txtRate.DataBindings.Add("Text", dataTable, "CurrencyRate");
 
Share this answer
 
Comments
CHill60 14-Dec-16 20:34pm    
Your "solution" is unclear... in what way is it any different to Solution 1 from 3 years ago? Erm, in no way

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