Create DataTable and Insert Row Programatically

/// DataTable Definition
dt.Columns.Add("TermId", typeof(string));
dt.Columns.Add("CourseId", typeof(string));
dt.Columns.Add("Section", typeof(string));
dt.Columns.Add("CourseCode", typeof(string));
dt.Columns.Add("TeacherId", typeof(string));
dt.Columns.Add("UserName", typeof(string));

/// DataTable Row value Insert
DataRow dRow = dt.NewRow();
dRow["TermId"] = hdnTermId.Value.ToString().Trim();
dRow["CourseId"] = hdnCourseId.Value.ToString().Trim();
dRow["Section"] = lblSection.Text.ToString().Trim();
dRow["CourseCode"] = leblCourseCode.Text.ToString().Trim();
dRow["TeacherId"] = lblCourseTeacherId.Text.ToString().Trim();
dRow["UserName"] = lblCourseTeacher.Text.ToString().Trim();

dt.Rows.Add(dRow);

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s