I\'m attempting to use the DataSet designer to create a datatable from a query. I got this down just fine. The query used returns a nullable datetime column from the datab
It seems different with DataTable and Strongly Typed DataTable... Use Like this.
DataSet1.DataTable1DataTable table = new DataSet1.DataTable1DataTable();
table.Merge(adapter.GetData().CopyToDataTable());
Thanks this solved my similar issue : Here is the code. In case of this question
Isevent_start_date()
//Table's Name is Efforts,
//Column's name is Target
//So the dataset would automatically generate a property called IsTargetNull() which can be used to check nullables
//Create an Adaptor
EffortsTableAdapter ad = new EffortsTableAdapter();
ProjectDashBoard.Db.EffortsDataTable efforts = ad.GetData();
DataColumn targetColumn = new DataColumn();
targetColumn = efforts.TargetColumn;
List<DateTime?> targetTime = new List<DateTime?>();
foreach (var item in efforts)
{
//----------------------------------------------------
//This is the line that we are discussing about :
DateTime? myDateTime = item.IsTargetNull() ? null : (DateTime?)item.Target;
//----------------------------------------------------
targetTime.Add(myDateTime);
}
I did this to insert value NULL
in a DateTime
column,
assuming that I have a nullable DateTime
column in Database, I retrieved some data from the database in an object called response
and I want to insert nullable DateTime
value in the DataSet column that called RenewDate
:
// create anew row of the same type of your table row
var rw = ds.StudentActionPrintDT.NewStudentActionPrintDTRow();
// check for null value
if(!response.RenewDate.HasValue)
{
// if null, then the let DataSet to set it null by it's own way
rw.SetRenewDateNull();
}
else
{
// if not null set value to the datetime value
rw.RenewDate = response.RenewDate.Value;
}
// add the created row to the dateset [DataSetName].[ColumnName].Add[ColumnName]Row([The Created Row]);
ds.StudentActionPrintDT.AddStudentActionPrintDTRow(rw);