I am new to the programming and i have some doubts about programming in c# wpf. Until now i used a programming without using patterns(mvvm, mvm, mvc etc). Based on some research i did on internet i've noticed that is better if i use different model pattern views. Until now i used some of these code for example:
SqlConnection con = new SqlConnection("Server = localhost;Database = Bilanc; Integrated Security = true");
SqlCommand cmd = new SqlCommand("Product", con); // Using a Store Procedure.
cmd.CommandType = CommandType.StoredProcedure;
cmd.Parameters.AddWithValue("Barcode", txtcode.Text);
dtg.ItemsSource = dataTable.DefaultView;//Set th
con.Open();//Open the SQL connection
SqlDataReader reader = cmd.ExecuteReader();//Create a SqlDataReader
while (reader.Read())//For each row that the SQL query returns do
{
DataRow dr = dataTable.NewRow();//Create new DataRow to populate the DataTable (which is currently binded to the DataGrid)
dr[0] = reader[0];//Fill DataTable column 0 current row (Product) with reader[0] (Product from sql)
dr[1] = reader[1];
dr[2] = reader[2];
dr[3] = reader[3];
dr[4] = reader[4];
dataTable.Rows.Add(dr);//Add the new created DataRow to the DataTable
txtkodi.Text = "";
object sumObject;
sumObject = dataTable.Compute("Sum(Total)", "");
txttot.Text = sumObject.ToString();
}
This is a part of code i used. Could someone of you explain how better is (mvvm, mvc) to use to improve or make better the coding. I am learning about programming and i need also to learn about these models.
I am asking because a developer told me that:Why are you working with a DataTable object as your model? Hasn't your instructor taught you about the MVVM pattern?( i had the same code , and he said these to me