Okay so the totourials I've been following to make my application have been based on the winforms side of c# where as my app has been based on wpf. However even though my app works fine, I'm told that there's a better way of binding my textboxes using MVVM. I however have been having a difficultt time finding MySQL related totourials that are wpf based that cover MVVM data-binding.
This is my current way of doing things, and so far it works. Apparently it could be better...
string sqlcon = "datasource = localhost; port = 3306; username = root; password = root";
string query = "Select * from users.login where tag = '" + this.tag.Text + "' ;";
new MySqlConnection(sqlcon);
MySqlCommand cmd = new MySqlCommand(query, con);
MySqlDataReader rdr;
try
{
con.Open();
rdr = cmd.ExecuteReader();
MessageBox.Show("Saved");
while (rdr.Read())
{
//Declarations
string susername = GetString(rdr, "username");
string spassword = GetString(rdr, "password");
string ssecurity = GetString(rdr, "question");
string sanswer = GetString(rdr, "answer");
//Binding strings to textboxes
username.Text = susername;
password.Text = spassword;
question.Text = ssecurity;
answer.Text = sanswer;
}
con.Close();
}
catch (Exception ex)
{
MessageBox.Show(ex.Message);
}
}
Maybe I'm not looking in the right places but I couldn't find anything specific on MySQL data-binding that had anything to do with xaml. What would be the best way to do this in wpf? Even just an example will do fine. Just so I can get an idea at least.