Monday, January 29, 2018

How do you find the value of this JSON object --- {"70":27.4"} ?

These are two validated JSON objects:

I am trying to find the value for the second JSON object:
The code shown at the end works and provides a value of 2.85
----------------------
var jobj2={"tuesday":"2.85"};
alert(jobj2.tuesday );//---alerts 2.85

------------------------------------
If I use the exact code that I used for recovering the value for the first JSON object, I end up with an error.
---------------
var obj2={"70":"27.4"};
alert(obj2.70);//--spawns an error
--------------------
The work around which I guessed that would work for the first object provides the value 27.4

var x;
x=70;
var obj={"x":"27.4"};
alert(obj.x);----//alerts 27.4

---------------------------------------

If you want to take a look, just take out the relevant comments and run. There could be a better way of resolving this rather than re-formatting the question.


Sunday, January 28, 2018

How do you store an array in Local Storage?

My previous post showed how to store a single piece of information in Local Storage (Browser Storage). However instead of a single piece of data you want to store an array of items.
Let us say your array has three elements, rose, jasmine and hyacinth and you want to store in an array named 'flowers'.
The following page shows how you may store array and retrieve array elements using JavaScript. Each statement is commented (view image magnified, if necessary).


ArrayStoreLocalStorage.png

Place this page in IIS's wwwroot folder and browse. You can see the elements in the array in LocalStorage.


ArrayStoreLocalStorage1.png

You can see more clearly here in the Microsoft Edge's developer window. Data stored from the previous post is also seen.



ArrayStoreLocalStorage2.png

Saturday, January 27, 2018

How do you store data in Local Storage?

Local Storage is supported if you use HTML. First of all you should make sure that your browser supports Local Storage. Data is stored as NAME,VALUE pairs in local storage.

You can review this post.

Let us say you want to store the string "Hi, Good Morning". You need to create a NAME \ VALUE pair, your VALUE being "Hi, Good morning" and the NAME can be anything. In the present example the NAME is "Greetings".

All you need to do is create a web page (just HTML) shown here:

Greetings.png

When you browse this page on your local IIS Server (localhost), you will see the greeting:



Friday, January 26, 2018

Can you use JSON for any SQL Server compatiblity level?

It has got to be compatibility level 130 or higher. It will fail otherwise.
You may change the compatibility level and then you can use JSON.

Read here:
https://hodentekmsss.blogspot.com/2016/11/change-compatibility-level-of-database.html

Compatibility level can be changed in SQL Server Management Studio.

SQL Server 2017: The compatibility level for Northwind (SqlServer 2008(100) restored from a backup file from CodePlex site is the following:



Change compatibility level using drop-down in the above.

Wednesday, January 24, 2018

How do you return JSON formatted response to a SQL Query?

JSON is supported in SQL Server and it is very easy to obtain JSON formatted response from a query easily. For example,

while connected to Northwind database you get the JSON formatted data by running a query such as this one using the Products table:
---------------------------------
SELECT        ProductName, QuantityPerUnit, UnitPrice
FROM            Products FOR JSON Auto;

---------------------------------
The response will be as shown:


JSON_0

You could also return a single row of data as shown by running this query:
-----------------------
SELECT [ProductID]
      ,[ProductName] 
FROM [Northwind].[dbo].[Products]
WHERE ProductID=5
For JSON AUTO

-------------------------


JSON_1


The result comes in an array even if the returned data is just one row.

You could remove the array wrapper ([ ]) surrounding the result set by the following query:
-------------------
SELECT [ProductID]
      ,[ProductName] 
FROM [Northwind].[dbo].[Products]
For JSON AUTO, WITHOUT_ARRAY_WRAPPER

---------------------------------------

JSON_2

Notice that the array wrapper is gone in the result set.

You can further qualify where the data (Which table, for example) by adding a 'root' element by issuing this query:
------------------------
SELECT [ProductID]
      ,[ProductName] 
FROM [Northwind].[dbo].[Products]
For JSON AUTO, Root('Products')

------------------------

JSON_3

You are not allowed to use WITHOUT_ARRAY_WRAPPER and Root in the same sql query because you get the following message, if you do:

Msg 13620, Level 16, State 1, Line 5
ROOT option and WITHOUT_ARRAY_WRAPPER option cannot be used together in FOR JSON. Remove one of these options.


I am using SQL Server 2016 Developer's edition on my Windows 10 Pro laptop.

If you are new to JSON read the following:

http://hodentekhelp.blogspot.com/2014/11/how-do-you-work-with-javascript-object.html

If you are motivated to learn there are more here:

http://hodentekhelp.blogspot.com/search?q=json

Tuesday, January 23, 2018

How can I connect to SQL Server with an IP Address using Microsoft Operations Studio?

Take for example, SQL Server 2017 Developer's edition. It is the latest release version. When you install it you can only access using 'localhost' as shown.

Enter localhost
SQLServrConfig0

Click Connect and you are connected as shown.


SQLServrConfig00

Now instead of localhost, try the IPAddress as shown.


SQLServrConfig4

Trying to Connect you get the following message.


The reason for this is that the Protocols for MSSQLSERVER (the instance we are considering) has only Shared Memory enabled as in the SQL Server Configuration Manager.

SQLServrConfig1

The error message indicated that it was due to Named Pipe provider error.

Let us enable Named Pipes protocol in SQL Server Configuration Manager as shown.

SQLServrConfig2

Make a note that when you change (enable/disable), you need to stop and start the server. You can do this in SQL Server Configuration Manager.

Now attempt to connect using IPAddress as before.

SQLServrConfig4

Click Connect and you are connected as shown.


SQLServrConfig3

That is all there is to it. 

Monday, January 22, 2018

How do you restore a database from its backup using Microsoft SQL Operations Studio?

It is quite easy. In fact you can restore Northwind database from the CodePlex site to SQL Server 2017 Developers edition.

Watch this video on YouTube:
https://www.youtube.com/edit?o=U&video_id=-KOXjlRACSU

Read this post of how you may do this using SQL Server Management Studio:
http://hodentekhelp.blogspot.com/2017/07/how-do-you-restore-database-from-its.html


If you are interested in installing SQL Server 2017 Developer Edition on Windows 10 Pro.
Read this post:
https://hodentekmsss.blogspot.com/2017/12/installing-sql-server-2017-developer-on.html

Restore using Windows PowerShell:
https://hodentekmsss.blogspot.com/2016/03/easy-way-to-backup-sql-server-database.html

Friday, January 19, 2018

There are no user databases in my SQL Server 2017, can I connect to it using Microsoft SQL Operations Studio?

Yes you can. There are already system databases. Make sure that the server has started. Start it if it has not started in Control Panel, or otherwise.

I have a default instance of SQL Server 2017 Verion 17.3 and I connect to it as described here.

Launch SQLOPS from its shortcut and click New Connection as shown


SQLServer17SQLOPS_0


The New Connection window opens as shown.


SQLServer17SQLOPS_1


Enter the items as shown.


SQLServer17SQLOPS_3

Click Connect.
You are connected as shown.




Click New Query to open a new query window as shown.


SQLServer17SQLOPS_6


Type S and a drop-down list appears.


SQLServer17SQLOPS_7



Complete a query as shown:

SELECT @@version


SQLServer17SQLOPS_8

Click Run and review the result as shown:


SQLServer17SQLOPS_9

Right click the result, copy and paste it in Notepad as shown:

Microsoft SQL Server 2017 (RTM) - 14.0.1000.169 (X64)  Aug 22 2017 17:04:49  Copyright (C) 2017 Microsoft Corporation Developer Edition (64-bit) on Windows 10 Pro Insider Preview 10.0 (Build 17025: ) (Hypervisor)

Note: It was mentioned that you type in msdb as a database. In fact just localhost is all that is neccessary to connect.

Sunday, January 14, 2018

Are there many versions of Windows 10 emulators?

Yes indeed. There are various versions for Windows 10 as well as for even earlier Windows versions.

Here are the ones for Windows 10:

10.1.15254.1


10.1.15063.137


10.1.14393.0


10.1.10586.11


10.0.26624.0


You may download them from this site here.

Wednesday, January 10, 2018

How would I add an app icon to my Universal Windows Project using Visual Studio 2017?

On smart phones Windows 10 Mobile, iPhone, Pixel Phones etc users immediately get to the app by clicking the app icon. It is their point of entry. Also when you install a new app, the new app appears on the app list.

For our HelloWorld Universal Windows Project, we can add the app icon (by replacing the default) using Visual Studio 2017 Community (or any other similar Visual Studio version).

If you are using the default app icon, when deployed your app would appear as shown here.


Lumia950AppIcon_0


It is pretty ugly (the icon of Hello World) and I am sure you want something that is distinctive of your development or company. You need to create an image to replace the "x" in your app.

I used Logo Foundry app that you can download from here. You can use any other software. It is just I found it the first time I searched and used it.

http://www.logomakerapp.com/index.html

I used it to create a simple logo that has the text 'Hodentek' on it as shown here:




Lumia950AppIcon_1

By using a photo application, I sliced it and created a 88x88 sized image recommended for the app icon in Visual Studio.

You should see this in the Package.appxmanifest file under Visual Assets | App Icon as shown.

I used the Browse(...) button for the recommended 88x88 size and retrieved to Visual Studio from the saved location.




Now from File menu click Save All. The build and run deploy the application to  Local Computer.

The application runs and the Hello World app icon appears as shown in Windows All programs as shown.






Tuesday, January 9, 2018

How do you deploy a Universal Windows Project to a connected device?

We will be using the Lumia 950 as the connected device and it has been set to Developer Mode as described earlier.

We start with the HelloWorld Universal Windows Project(UWP) that has been tested to run without errors on the Local Machine as described here.

Open the project in Visual Studio 2017 as shown.



LumiaDeploy_0 and LumiaDeploy_7

Build (Using Menu Build and its context menu) the Project and verify it is successful.
--------
1>------ Build started: Project: HelloWorld, Configuration: Debug x86 ------
1>  HelloWorld -> C:\Users\Owner\source\repos\HelloWorld\HelloWorld\bin\x86\Debug\HelloWorld.exe
========== Build: 1 succeeded, 0 failed, 0 up-to-date, 0 skipped =====
------------------

Click Local Machine along Debug as shown.


LumiaDeploy_1

Pick Device from the list, the display changes as shown.



LumiaDeploy_2

Connect your Windows 10 Mobile(Lumia 950) to one of the USB ports.


This will result in an error as it is not x64 architecture.
LumiaDeploy_9

Pick ARM from the list.

Click Configuration Manager... to display the Configuration Manager window as shown.


LumiaDeploy_4

Make sure configuration is as shown above.

Click Build and from drop-down click Deploy.


Deploy succeeds and you should see the HelloWorld app appears in the apps list.

Here are the deployed apps on Lumia 950


 After clicking 'Hello'


What is required to deploy a Universal Windows Project to Lumia 950?

One of the requirements is that your phone should be configured so that UWP can be deployed. 
The configuration needs to be modified on the phone using SETTINGS as described here. If you are a registered then you can use the developer mode.

I deploy my UWP apps to Microsoft Lumia 950. One of the first things you need to do is to set it for Developers.

There are three options and you should choose Developer mode as shown here:


Lumia950_0

You should turm on option to make your phone visible to USB connections to your local network as shown here:


Lumia950_1

Also turn on remote diagnostics over USB and authentication as shown above.


Lumia950_2

Now you can connect the Windows 10 Mobile(=Lumia 950) to one of the USB connections on your laptop/computer where you are running Visual Studio 2017 used for creating Universal Windows Projects. You set up your project deploying it to the device.

Here are my phone details:
Microsoft Lumia 950
Version 1709
Windows 10 Mobile
OS Build:10.0.15254.124
Screen Res: 1440x2560

Here is HelloWorld deployed to Lumia950


Lumia950_3

Sunday, January 7, 2018

How do you change the BACKGROUND color of a XAML button using a CLICK event in C#?

Sometimes you need to change the background color from its default to a different color. Let us say, we have a button whose Background color needs changing by an event such as the CLICK event.

How is it done?
Well, I could give you a line of code to do that. Perhaps it will work and all that there is to it. However, if you are beginner and wondering how the hell it is coded with so much of background code, namespaces; classes, methods, events etc.

This post tries to show how you may find yourselves how to do it.

If you are looking for the one line of code, please go to the end and you will find it there. If you are beginning to code and new to Microsoft; new to Visual Studio in particular, follow on.

As mentioned in my previous post Universal Windows Project use XAML for the UI and the pages.
Some of the things you should remember is that you should use intellisense as much as possible. You should also use code hints you get when your code is not doing what you except.

In order to illustrate let us start with the code for a BUTTON click event for a button named ClickMe as shown:
=========
public sealed partial class MainPage : Page
    {
        public MainPage()
        {
            this.InitializeComponent();
        }

    
        private void ClickMe_Click(object sender, RoutedEventArgs e)
        {
            ClickMe.FontSize = 50;
           
        }
    }
}

===============

The above code changes the font-size to 50 when the button is clicked. We add one more line which changes the BACKGROUND color to red.

Start with ClickMe (the object) by typing below ClickMe in the above code.

As soon as you typein Click you will see this:


ClickMeEvent_0

Pick ClickMe from the above and add a period to it after that and you will get more pop-up as shown.


ClickMeEvent_1

Pick Background and your code looks like this:


ClickMeEvent_3

You try the 'dot trick' again by typing a dot after Background as shown. You do get a pop-up which does not seem to have anything to do with color.


ClickMeEvent_4

Now you need to know that color is given by using a brush and you have an Object called SolidColorBrush besides other kinds. In XAML scenarios, Color is not referenced directly but by the component SolidColorBrush.


ClickMeEvent_5

Now you type in SolidColorBrush but you get the red wiggly (oops, something not right).


ClickMeEvent_6

You place your cursor on SolidColorBrush and you get a hint. SolidColorBrush is a class name and you are looking for a color value. Instead of using the class, you should use an instant of the class with the 'new' keyword as shown.


ClickMeEvent_7

The red wiggly is still there but you have made progress.

Well this gives a hint that you must follow up this with one of [], {},or ().

Let us type the parenthesis-begin as shown


ClickMeEvent_8

There are two options as shown.


ClickMeEvent_9

The first method gives no color and the second options uses one of the Windows colors.


ClickMeEvent_10.jpg

Now I use the hint from the image one previous to the above. And we continue with code as shown.


ClickMeEvent_11.jpg

Well, again we are getting the class COLOR. Place the cursor on the color and find out what is needed.

Now with the dot trick we are ahead to choose a color we want.


ClickMeEvent_12.jpg

Now we have to choose the color from inserting proper values for the arguments of the function
FromArgb() as described in this post here.

Let us choose a ALPHA (transparency)channel value of 255 and a RED channel value of 255, BLUE channel value 0 and Green channel vlaue of 0 as shown. Type these into FromArgb() as shown.


ClickMeEvent_14.jpg

Now we are rid of the pesky red wiggly line. Ready to rock and roll.

Build the code from the main menu and deploy it to the local machine as described in my earlier post.

The Build succeeds as shown.


ClickMeEvent_15.jpg

Now Deploy the solution and you get this result as there are no errors:
========
Deploy started: Project: HelloWorld, Configuration: Debug x86 ------
Updating the layout...
Copying files: Total <1 br="" layout...="" mb="" to="">1>Checking whether required frameworks are installed...
Registering the application to run from layout...
Deployment complete (0:00:18.287). Full package name: "b940c521-2fb5-429c-9486-69bb2a425e90_1.0.0.0_x86__ckpvgz13cfhxc"

========== Build: 0 succeeded, 0 failed, 1 up-to-date, 0 skipped ==========
========== Deploy: 1 succeeded, 0 failed, 0 skipped ==========
Now run the project and you get this display of  your application
<1 br="" layout...="" mb="" to="">

<1 br="" layout...="" mb="" to="">
<1 br="" layout...="" mb="" to="">ClickMeEvent_16

Now click the Hello button to see the Background color and font size change as shown.


ClickMeEvent_17

After verifying close the application and you get the following response:
==================
The program '[15840] HelloWorld.exe' has exited with code 1 (0x1).

That's it folks!