protected void WebDataGrid1_RowAdding(object sender, Infragistics.Web.UI.GridControls.RowAddingEventArgs e) { SqlConnection con = new SqlConnection(connectionString); SqlCommand cmd = new SqlCommand("InsertDailyElectricityDetails", con); con.Open(); cmd.CommandType = CommandType.StoredProcedure; cmd.Parameters.AddWithValue("@machine", WebDataGrid1.Rows[0].Items[1].Value); cmd.Parameters.AddWithValue("@lastdayreading", WebDataGrid1.Rows[0].Items[2].Value); cmd.Parameters.AddWithValue("@currentdayreading", WebDataGrid1.Rows[0].Items[3].Value); cmd.ExecuteNonQuery(); con.Close(); }
ALTER PROCEDURE dbo.InsertDailyElectricityDetails ( @machine varchar, @lastdayreading DECIMAL, @currentdayreading DECIMAL ) AS INSERT INTO ElectricityDailyMeterReadings (MachineID,LastDayMeterReading,CurrentDayMeterReading,Consumption) VALUES (@machine,@lastdayreading,@currentdayreading,@currentdayreading - @lastdayreading) RETURN