1 Attachment(s)
[RESOLVED] Problem Updating Datagridview[2.0]
Good Morning All
I have a Datagridview in a Windows application, am having a Problem updating the Gridview. First the Code does not Bring Errors, its only a logical Error. Now i have a Function that does the Update and its Written like this
Code:
public void Update_Records(DataSet dsdata)
{
da = new SqlDataAdapter();
con = new SqlConnection(strcon);
cmdupdate = new SqlCommand();
cmdupdate.CommandType = CommandType.StoredProcedure;
cmdupdate.CommandText = "Update_Status_Grid";
cmdupdate.CommandTimeout = 0;
cmdupdate.Connection = con;
cmdupdate.Parameters.Add("@Original_Pro_id",SqlDbType.Int,4,"Pro_id");
cmdupdate.Parameters["@Original_Pro_id"].SourceVersion = DataRowVersion.Original;
cmdupdate.Parameters.Add("@Original_Delivered",SqlDbType.Int,4,"Delivered");
cmdupdate.Parameters["@Original_Delivered"].SourceVersion = DataRowVersion.Original;
da.UpdateCommand = cmdupdate;
try
{
con.Open();
da.Update(dsdata, "Products");
con.Close();
}
catch (SqlException e)
{
MessageBox.Show(e.Message);
}
}
Now i have a Button in my Form to update the Grid like this
Code:
try
{
if (dsdata.HasChanges())
{
Update_Records(dsdata);
MessageBox.Show("Records Updated");
}
else
{
MessageBox.Show("No Changes Made, So you cannot Save");
}
}
catch (ApplicationException ex)
{
MessageBox.Show(ex.Message);
}
All this uses the Following StoredProcedure that i wrote like this
Code:
USE [ValRollClients]
GO
/****** Object: StoredProcedure [dbo].[Update_Status_Grid] Script Date: 07/03/2008 08:21:22 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
--Update Stored Procedure
ALTER PROCEDURE [dbo].[Update_Status_Grid]
(--Carry Original values before Update
@Original_Pro_id int,
@Original_Delivered int = null
)
as
Update Products
set Delivered = NUll
where (Pro_ID = @Original_Pro_id )
And (Delivered = @Original_Delivered
OR @Original_Delivered Is Null And Delivered Is Null)
--Refreshing Data
;
select p.Pro_id,p.Client_ID,p.Prod_Name as [Product Name],
p.Prod_Description as [Description],
p.Price,c.Client_Name, p.Delivered from Products p
inner Join Client_Details c on
p.Client_ID = c.Client_ID
where (Pro_id = @Original_Pro_id )
but now my problem is one, if there was a value in the Delivered Field, then the Update is going to be Successfully, but if there was Null Value then the Update will Execute without any Error, but the Field will still be Null and never Updated. Even when i Click the Update Button the Datagridview, just ignore the Field as is it were a Readonly. I have attached an example of my Problem as a Screenshot.
What is Wrong
Thanks