Python retrieve data from SQL Server

This blog article shows you how to connect Python to SQL Server. First you need to make Python run in Visual Studio https://chanmingman.wordpress.com/2020/11/15/python-using-visual-studio-2019/. You also need to have SQL Server install with nothwind database. Go to the Python folder where you installed your Python and type in the follow command to install pyodbc.

pip install pyodbc


Put the code below in Visual Studio.

import pyodbc

conn = pyodbc.connect(‘Driver={SQL Server};’

        ‘Server=.;’

        ‘Database=northwind;’

        ‘Trusted_Connection=yes;’)

cursor = conn.cursor()

cursor.execute(‘SELECT * FROM Products’)

for row in cursor:

    print(row)


You can get back your result when you run.


Source code download: https://github.com/chanmmn/PythonSQLServer

Reference: https://docs.microsoft.com/en-us/learn/modules/intro-to-python/?WT.mc_id=DP-MVP-36769

Posted in .Net, Cloud, Community, Computers and Internet, Data Platform | Tagged , | Leave a comment

Pin the program from Desktop to Start Menu Windows 10

This blog article shows you how to Pin your desktop item to Start Menu (Pin to Start). First you need to drag your desktop program using Right mouse button to C:\Users\YourAccount\AppData\Roaming\Microsoft\Windows\Start Menu\Programs. Choose Create shortcuts here.

Click Start button from your Windows 10 to find the item. Right click the item and choose Pin to Start.

Posted in .Net, Cloud, Community, Computers and Internet, Operating System | Tagged | Leave a comment

Merge Sort C++

This blog article shows you a working merge sort using C++. There are many code snippets out there but not everyone of them work. I have gotten a code from here https://www.softwaretestinghelp.com/merge-sort/ and tried to insert them in C++, this snippet works.

#include <iostream>

using namespace std;

void merge(int*, int, int, int);

void merge_sort(int* arr, int low, int high)

{

    int mid;

    if (low < high) {

        //divide the array at mid and sort independently using merge sort

        mid = (low + high) / 2;

        merge_sort(arr, low, mid);

        merge_sort(arr, mid + 1, high);

        //merge or conquer sorted arrays

        merge(arr, low, high, mid);

    }

}

// Merge sort

void merge(int* arr, int low, int high, int mid)

{

    int i, j, k, c[50];

    i = low;

    k = low;

    j = mid + 1;

    while (i <= mid && j <= high) {

        if (arr[i] < arr[j]) {

            c[k] = arr[i];

            k++;

            i++;

        }

        else {

            c[k] = arr[j];

            k++;

            j++;

        }

    }

    while (i <= mid) {

        c[k] = arr[i];

        k++;

        i++;

    }

    while (j <= high) {

        c[k] = arr[j];

        k++;

        j++;

    }

    for (i = low; i < k; i++) {

        arr[i] = c[i];

    }

}

// read input array and call mergesort

int main()

{

    int myarray[30], num;

    cout << “Enter number of elements to be sorted:”;

    cin >> num;

    cout << “Enter ” << num << ” elements to be sorted:”;

    for (int i = 0; i < num; i++) {

        cin >> myarray[i];

    }

    merge_sort(myarray, 0, num – 1);

    cout << “Sorted array\n”;

    for (int i = 0; i < num; i++)

    {

        cout << myarray[i] << “\t”;

    }

}


Download the code for Visual Studio here: https://github.com/chanmmn/MergeSortCpp

Reference: https://docs.microsoft.com/en-us/cpp/?view=msvc-160&viewFallbackFrom=msvc-160%2F%3FWT.mc_id%3DDP-MVP-36769

Posted in .Net, Cloud, Community, Computers and Internet | Tagged | Leave a comment

exePath must be specified when not running inside a stand alone exe

This blog article shows one of the possible ways to fix the error above and Add key and value to Web.config during runtime. In the article, https://chanmingman.wordpress.com/2020/11/09/add-value-to-app-config-during-runtime/, shows you how to Add key and value to App.config during runtime using the code fragment below.

Configuration config = ConfigurationManager.OpenExeConfiguration(ConfigurationUserLevel.None);

You will get the follow error if you are changing Web.config in Webform or WCF.

System.ArgumentException

HResult=0x80070057

Message=exePath must be specified when not running inside a stand alone exe.

Source=<Cannot evaluate the exception source>

StackTrace:

<Cannot evaluate the exception stack trace>

For Web.config you need to use the code below.

Configuration config = System.Web.Configuration.WebConfigurationManager.OpenWebConfiguration(“~”);


Reference: https://stackoverflow.com/questions/16720576/exepath-must-be-specified-when-not-running-inside-a-stand-alone-exe

Posted in .Net, Cloud, Community, Computers and Internet | Tagged , | Leave a comment

CTO November 2020 articles and resources

These are the good reads found in this month.

Here’s A Hint About How Few People Click Those “Do Not Sell My Personal Information” Links

https://www.forbes.com/sites/robpegoraro/2020/11/13/heres-a-hint-about-how-few-people-click-those-do-not-sell-my-personal-information-links/?ss=bigdata&sh=3a80f1111fc9

6 hidden risks of IT automation

  1. Automating processes before optimizing them
  2. Allowing ‘automation complacency’ to take hold
  3. Poor communication among stakeholders
  4. Process automation misfit
  5. Overlooking end user input
  6. No consideration of interaction design

https://www.cio.com/article/3596309/6-hidden-risks-of-it-automation.html?upd=1605443153786

Digital transformation: The difference between success and failure

https://www.zdnet.com/article/digital-transformation-spotting-the-winners-and-losers-in-2020/

Ready, set, change! Building a fair, equitable and just IT culture

https://www.cio.com/article/3587605/ready-set-change-building-a-fair-equitable-and-just-it-culture.html

The value of and myths about enterprise architecture

Some researchers have even stated that architecture should only be prescriptive and no description of the current situation is necessary to develop a strategy (Hoogervorst, 2004). However, if these claims appear in isolation, it might lead to an overemphasis on the future situation. Moreover, there is often no greenfield, and creating new systems might only make the landscape less coherent and result in more fragmentation. If you do not know where you stand, you also do not know which direction you should take in order to reach your destination.

https://www.sciencedirect.com/science/article/pii/S0268401217305492

Resources

Gartner Magic Quadrant for Operational Database Management Systems https://gtnr.it/3349DVM

Posted in .Net, Cloud, Community, Computers and Internet, CTO, Data Platform | Tagged , , | Leave a comment

Python resources

This blog article shows you the Python programing resources.

Introduction to Python

https://docs.microsoft.com/en-us/learn/modules/intro-to-python/?WT.mc_id=DP-MVP-36769

Get started using Python on Windows for scripting and automation

https://docs.microsoft.com/en-us/windows/python/scripting/?WT.mc_id=DP-MVP-36769

Azure Functions Python developer guide

https://docs.microsoft.com/en-us/azure/azure-functions/functions-reference-python/?WT.mc_id=DP-MVP-36769

How to install Python support in Visual Studio on Windows

https://docs.microsoft.com/en-us/visualstudio/python/installing-python-support-in-visual-studio?view=vs-2019/?WT.mc_id=DP-MVP-36769

Python SQL Driver

https://docs.microsoft.com/en-us/sql/connect/python/python-driver-for-sql-server?view=sql-server-ver15/?WT.mc_id=DP-MVP-36769

Step 1: Configure development environment for pyodbc Python development

https://docs.microsoft.com/en-us/sql/connect/python/pyodbc/step-1-configure-development-environment-for-pyodbc-python-development?view=sql-server-ver15/?WT.mc_id=DP-MVP-36769

Posted in .Net, Cloud, Community, Computers and Internet, Data Platform | Tagged , | Leave a comment

Blazor hide Div

This blog article shows you how to hide a div html element using C# in Blazor. This article expects you have the basic knowledge of Blazor. Create a Razor Component with the follow html.

<div hidden=”@IsShow“>

    <h3>Edit Product</h3>

    Product Name<br/>

    <p><input class=”form-control” @bind=”ProdName/></p>

    Price<br />

    <p><input class=”form-control” @bind=”UnitPrice/></p>

</div>

In the C# code area put in the follow code.

@code
{

    private bool IsShow { get; set; } = true;

    private float UnitPrice { get; set; }

    public string ProdName { get; set; }

    private void Show()

    {

        IsShow = !IsShow;

    }

}

You can run the solution and see the effect, like the one below.


You can find the hiding code in Product.razor page in the solution below.

Source Code Download https://github.com/chanmmn/BlazorHideDiv

Reference: https://www.syncfusion.com/faq/blazor/data-binding/how-do-you-conditionally-hide-the-dom-elements

Posted in .Net, Cloud, Community, Computers and Internet | Tagged | Leave a comment

Python using Visual Studio 2019

This blog article shows you how to code and run Python using Visual Studio 2019. Start Visual Studio, select Create a new project, In the search box type python. Then choose Python Applicaton.

Simply type the follow code.

print(“Hello world.”)

When you run then Visual Studio might complains you does not have python install. Click the Download and install Python.

The installation will begin.

You can now run the python code after the installation, using Visual Studio.

Resources: Introduction to Python, https://docs.microsoft.com/en-us/learn/modules/intro-to-python/?WT.mc_id=DP-MVP-36769

Posted in .Net, Cloud, Community, Computers and Internet | Tagged , | 1 Comment

SQL Server add Parameter for IN keyword

This blog article shows you how to put the value in the SQL Statement IN keyword in C# SqlParameter. This article expect you know have basic SQL Server and C# knowledge. Supposed you have a sql statement as the one below.

string sqlread = “SELECT * FROM [dbo].[Products] Where CategoryID IN (1,2)”;

You want to turn the 1,2 into a SqlParameter. So you are trying this.

string sqlread = “SELECT * FROM [dbo].[Products] Where CategoryID IN (@para3)”;

then

cmd.Parameters.Add(“@para2”, SqlDbType.VarChar,20);

cmd.Parameters[“@para2”].Value = “1,2”;

dr = cmd.ExecuteReader();

Too bad, you will get the error like below.


The correct way to do this is like the code snippet below.

string strConn = “data source=.;initial catalog=northwind;integrated security=True”;

string sqlread = “SELECT * FROM [dbo].[Products] Where CategoryID IN (@para1,@para2)”;

SqlConnection conn = new SqlConnection(strConn);

SqlDataReader dr = null;

using (conn)

{

    conn.Open();

    using (SqlCommand cmd = new SqlCommand(sqlread,conn))

    {

        cmd.Parameters.Add(“@para1”, SqlDbType.Int);

        cmd.Parameters[“@para1”].Value = 1;

        cmd.Parameters.Add(“@para2”, SqlDbType.Int);

        cmd.Parameters[“@para2”].Value = 2;

        dr = cmd.ExecuteReader();

        if (dr.Read())

        {

            Console.WriteLine(dr[0].ToString());

        }

    }

}

You can download the source code and play with it using the download link as follow.

Source Code download: https://github.com/chanmmn/SqlParameterINKeyword

Reference: https://docs.microsoft.com/en-us/dotnet/api/microsoft.data.sqlclient.sqlparameter?view=sqlclient-dotnet-core-2.0/?WT.mc_id=DP-MVP-36769

Posted in .Net, Cloud, Community, Computers and Internet, Data Platform | Tagged , | Leave a comment

Microsoft Word 2019 Read Aloud setting

This short blog article shows you where to configure the Read Aloud in Microsoft Word 2019. You do not need to go to Control Panel.

Posted in .Net, Cloud, Community, Computers and Internet, Office 365 | Tagged | Leave a comment