Technical Insights: Azure, .NET, Dynamics 365 & EV Charging Architecture

Tag: ASP.NET

Iterate by Index in DataTable

This post will explain how to iterate through datatable and how to get value based on index.


//This function is used to iterate through datatable
private void GetAllRows(DataSet ds){
   // iterate through table in the DataSet
get the values of each row.

   foreach(DataTable currTable in ds.Tables){
      // iterate through row
      foreach(DataRow currRow in currTable.Rows){
//iterate through column
         foreach(DataColumn currCol in currTable.Columns){
            Console.WriteLine(currRow[currCol]);
         }
       }
   }
}

//This one line of code is used to access based on row and column index.
currTable.Rows[0][1]      --- represents the value in first row and second

How to remove checked item in Checked Box List

At the moment, I’m learning towards win development. I got a very simple problem which is “Removing checked item on checked box list”. The first code below is throwing an error since you try to delete an item then on the postback it will reset the index. The real solution is on the second code

//this code is throwing an error about the index position
 private void btnRemove_Click(object sender, EventArgs e)
        {
            foreach (SMSData item in chkSmsList.CheckedItems)
            {
                chkSmsList.Items.Remove(item);
            }
        }

Fix

//this is the code which is working perfectly, basically this code always looking into the first item on the "CheckedItems" Stack
  private void btnRemove_Click(object sender, EventArgs e)
        {
            while (chkSmsList.CheckedItems.Count > 0)
            {
                chkSmsList.Items.Remove(chkSmsList.CheckedItems[0]);
            }
        }

Dynamic array in VB/VB.NET/ASP

Time to go back to old school ASP, I found that i need to create an array that contains a list of languages from a table in database. I would like to make this array length as many as the number of rows in language table. yes you can do it through keyword of ReDim and Preserve

     <%
                dim objLanguage
                dim languageCount
                dim languageArray()

                languageCount = 0

                set objLanguage = Server.CreateObject("ADODB.Recordset")
                objLanguage.ActiveConnection = MM_CTG_STRING
                objLanguage.Source = "SELECT * FROM Languages"
                objLanguage.CursorType = 0
                objLanguage.CursorLocation = 2
                objLanguage.LockType = 3
                objLanguage.Open()

                WHILE NOT objLanguage.EOF
                    response.Write("

") response.Write(objLanguage("Language")) response.Write("

") ReDim Preserve languageArray(languageCount) languageArray(languageCount) = objLanguage("LanguageID") languageCount = languageCount + 1 objLanguage.MoveNext() WEND objLanguage.Close() Set objLanguage = nothing %>

Powered by WordPress & Theme by Anders Norén