if (e.Key == Key.Enter) { 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 the DataGrid ItemSource to this new generated DataTable 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]; 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(); }
var
This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)