Problem in row adding event in Editing Core RowAdding Event

Nov 4 2013 3:16 AM
Hi i am using infragistics Web Grid for my website. I have load data from my data source successfully and now i want a help in adding data into my database using rowadding event in infragistics.. I tried following code,
 
 
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();
}
 
But thing is it gives following error 
 
**Object reference not set to an instance of an object
 
I have written my sql in a stored procedure and following is the query 
 
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
 
 
And finally i would like to mention that the table i am working with has only 5 rows already entered,
MachineID LastDayMeterReading CurrentDayMeterReading Consumption
M001 5.000000 10.000000 5.000000
M002 5.000000 15.000000 10.000000
M003 45.000000 60.000000 15.000000
M004 50.000000 100.000000 50.000000
M005 100.000000 200.000000 100.000000
 
Can some one help with this issue.. Some say i need a hashtable,rowcount ..etc.. but i have no idea about it..
 
Thanks in advance