Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8744215
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 13, 20262026-06-13T11:48:33+00:00 2026-06-13T11:48:33+00:00

I have code for filling my DataColumn s. but the for loop I created

  • 0

I have code for filling my DataColumns. but the for loop I created wont work.
The first DataTable is being filled with a SQL query. The second DataTable needs to be partially being filled with data from the first DataTable. So I built a second DataTable manually with a for loop to fill it, but it doesn’t work?

using System;
using System.IO;
using System.Text;
using System.Data;
using System.Data.Common;
using System.Data.SqlClient;
using System.Configuration;
using System.Linq;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Xml.Linq;
using System.ComponentModel;

public partial class _Planning : System.Web.UI.Page
{
ConnectionStringSettings Leerstoftabel;
SqlConnection connection;
int cursusID = 2;
DataTable LeerstofTabel;
DataTable Planning;


protected void Page_Load(object sender, EventArgs e)
{
Leerstoftabel = ConfigurationManager.ConnectionStrings["CursusPlanner"];
connection = new SqlConnection(Leerstoftabel.ConnectionString);

SqlCommand cmd = connection.CreateCommand();
cmd.CommandType = CommandType.Text;
cmd.CommandText = "SELECT cursus.naam AS [Cursus Naam], vak.vaknaam, cursusvak.volgnummer, les.dagnummer, les.hoofdstuknummer, les.naam AS [Les Naam], les.lesomschrijving FROM cursus INNER JOIN cursusvak ON cursus.cursusID = cursusvak.cursusID INNER JOIN vak ON cursusvak.vakID = vak.vakID INNER JOIN les ON vak.vakID = les.vakID WHERE(cursus.cursusID = @cursusID)ORDER BY cursusvak.volgnummer";

//int cursusID = Convert.ToInt32(DropDownList1.SelectedValue);
cmd.Parameters.Add("@cursusID", SqlDbType.Int, 0).Value = cursusID;

connection.Open();

//het creeëren van een datatabel
DbDataReader rdr = cmd.ExecuteReader();
LeerstofTabel = new DataTable();
LeerstofTabel.Load(rdr);

connection.Close();
}


protected void Calendar1_DayRender(object sender, DayRenderEventArgs e)
{
// weekend days can't be selected in calendar
if (e.Day.IsWeekend)
    e.Day.IsSelectable = false;
}

protected void Button1_Click(object sender, EventArgs e)
{
//create the DataTable named "Planning"
Planning = new DataTable ("Planning");

//Add the DataColumn using defaults
DataColumn datum = new DataColumn("Datum");
datum.DataType = typeof(DateTime);
datum.AllowDBNull = false;
datum.Caption = "Datum";
Planning.Columns.Add(datum);

//Add the DataColumn using defaults
DataColumn hoofdstuk = new DataColumn("Hoofdstuk");
hoofdstuk.AllowDBNull = false;
hoofdstuk.Caption = "Hoofdstuk";
Planning.Columns.Add(hoofdstuk);

//Add the DataColumn using defaults
DataColumn omschrijving = new DataColumn("Omschrijving");
omschrijving.AllowDBNull = false;
hoofdstuk.Caption = "Omschrijving";
Planning.Columns.Add(omschrijving);

//Add the DataColumn using defaults
DataColumn lessen = new DataColumn("Lessen");
lessen.AllowDBNull = false;
lessen.Caption = "Lessen";
Planning.Columns.Add(lessen);


for (int i = 0; i < LeerstofTabel.Rows.Count; i++)
{
    if (LeerstofTabel ["vaknaam"]).ToString() != vorigvak  // this statement doesn't work
    {
        DataRow newplannning = Planning.NewRow();
        newplannning["Datum"] = "";
        newplannning["Hoofdstuk"] = "*" + LeerstofTabel["vaknaam"];
        newplannning["Omschrijving"] = "";
        newplannning["Lessen"] = "";
        Planning.Rows.Add(newplannning);

    }

    Vorigvak = (LeerstofTabel["vaknaam"])ToString();
}


GridView1.DataSource = Planning;
GridView1.DataBind();
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-13T11:48:34+00:00Added an answer on June 13, 2026 at 11:48 am

    If vaknaam is your column name, you’ll need to use it on a row

    var r = LeerstofTabel.Rows[i]
    if (r["vaknaam"]).ToString() != vorigvak) { // ...
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have filled the listview using the code given below, but I'm unablee to
Hello i have this form filling javascript: function onLine(code,nn) { document.writeform.bericht.value+=code; document.writeform.bericht.focus(); document.writeform.nickname.value+=nn; write1();
So I have this piece of code, and let's assume I'm filling out a
I have code that generates a List<string[]> variable but can't quite figure out how
I have code that looks more or less like the code below but it
I have this code below. I randomly ran across that it will work if
I have my code setup to send me emails every time someone is filling
Possible Duplicate: Multiple select options in one row I have the following code but
I have created a Sub-Class of NSOutlineView and used the below code to make
I have written this code to make a binary file of float numbers, but

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.