问题描述:

Not sure if anyone has experience this issue. I have a TextBox that I have bound to a DataSet that I'm getting from a MySql database and it is populating the value but if I try changing the value it just reverts to the original value when I leave the textBox. Here is an example of my code:

string connectString = "Database=customerDatabase;Data Source=localhost"+

";port=3306;User Id=root;Password=datascan;Allow Zero DateTime=true";

MySqlConnection dataConnection = new MySqlConnection(connectString);

dataConnection.Open();

DataSet dataSet = new DataSet();

string query = "select programsUpdated from customers";

MySqlDataAdapter dataAdapter = new MySqlDataAdapter(query, dataConnection);

dataAdapter.Fill(dataSet);

dataConnection.Close();

BindingSource source = new BindingSource(dataSet, "Table");

textBox.DataBindings.Add("Text", source, "programsUpdated");

I tried putting textBox.DataBindings[0].WriteValue(); in the textBox.Leave event but that did nothing. And Ive researched it but haven't been able to find anyone with the same or even similar problem.

It seems to have something to do with the Type of the data that I'm binding which in this case is MySqlDateTime. I tested it with System.DateTime and the problem did not happen.

Any help would be appreciated

网友答案:

I cant believe I didnt think of this sooner, but I ended up using a DateTimePicker as opposed to a TextBox.

dateTimePicker.DataBindings.Add("Value", dataSet.Tables[0], "programsUpdated");
相关阅读:
Top