This is My Procedure..
alter PROCEDURE Sp_AssignProjectToUser
(
@Ref_UserID int = null
, @Ref_ProjectID int = null
, @ActiveFlag bit =null
)
AS
BEGIN
INSERT INTO UserMappingProject (Ref_UserID
, Ref_ProjectID
, ActiveFlag)
VALUES (@Ref_UserID, @Ref_ProjectID, @ActiveFlag)
END
This Is C# code
public int AssignProjectToUser(DataTable dtUserProjectMap, Int32 batchSize)
{
int Result = 0;
SqlConnection con = new SqlConnection(connectionString);
SqlCommand cmd = new SqlCommand("Sp_AssignProjectToUser", con);
cmd.Parameters.AddWithValue("@Ref_UserID", Ref_UserID);
cmd.Parameters.AddWithValue("@Ref_ProjectID", ProjectID);
cmd.Parameters.AddWithValue("@ActiveFlag ", flag);
con.Open();
cmd.CommandType = CommandType.StoredProcedure;
Result = cmd.ExecuteNonQuery();
con.Close();
return Result;
SqlDataAdapter adapter = new SqlDataAdapter();
adapter.UpdateCommand = new SqlCommand("Sp_AssignProjectToUser", con);
adapter.UpdateCommand.Parameters.Add("@Ref_UserID", SqlDbType.Int, 5, "Ref_UserID");
adapter.UpdateCommand.Parameters.Add("@Ref_ProjectID", SqlDbType.Int, 4, "Ref_ProjectID");
adapter.UpdateCommand.Parameters.Add("@ActiveFlag", SqlDbType.Bit, 1, "ActiveFlag");
adapter.UpdateCommand.UpdatedRowSource = UpdateRowSource.None;
adapter.UpdateBatchSize = 4;
Set the INSERT command and parameter.
adapter.InsertCommand = new SqlCommand("Sp_AssignProjectToUser", con);
adapter.InsertCommand.Parameters.AddWithValue("@Ref_UserID","Ref_UserID");
adapter.InsertCommand.Parameters.Add("@Ref_UserID", SqlDbType.Int, 5, "Ref_UserID");
adapter.InsertCommand.Parameters.Add("@Ref_ProjectID", SqlDbType.Int, 4, "Ref_ProjectID");
adapter.InsertCommand.Parameters.Add("@ActiveFlag", SqlDbType.Bit, 1, "ActiveFlag");
adapter.InsertCommand.UpdatedRowSource = UpdateRowSource.None;
adapter.UpdateBatchSize = batchSize;
adapter.Update(dtUserProjectMap);
return Result;
Showing That Error When I Insert Records.
Cannot insert the value NULL into column 'Ref_UserID', table 'ZP505_VersionControlTracker.dbo.UserMappingProject'; column does not allow nulls. INSERT fails.
Cannot insert the value NULL into column 'Ref_UserID', table 'ZP505_VersionControlTracker.dbo.UserMappingProject'; column does not allow nulls. INSERT fails.