I want to bind a text field to a single DataRow object (passed to the dialog form for editing). Here is my code:
DataRow row = myDataTable.NewRow();
EditForm form = new EditForm(row);
nameTextBox.DataBindings.Add("Text", row, "name");
and I get an error: cannot bind to a property or column in a DataSource. Do you know what I am missing or maybe some workarounds?
[Added]
My DataTable surely contains a DataColumn with ColumnName = "name". Here is my code for creating a DataTable
public DataTable SelectReturnDataTable(string tableName, string sql, params SQLiteParameter[] parameters)
{
using (SQLiteConnection conn = new SQLiteConnection(_connectionString))
{
using (SQLiteCommand cmd = new SQLiteCommand(conn))
{
cmd.CommandText = sql;
foreach (SQLiteParameter p in parameters)
cmd.Parameters.Add(p);
SQLiteDataAdapter da = new SQLiteDataAdapter(cmd);
DataTable dt = new DataTable(tableName);
conn.Open();
da.Fill(dt);
return dt;
}
}
}
source
share