Shalvin Interests

Sunday, February 1, 2026

Web API 10 Configure Swagger

Web API 10 doesn't come with default swagger support. It can be added by adding a reference to Swashbuckle.AspNetCode, registering the service, adding to middleware and making alterations to launchSettings.json.

 

image 

Program.cs
builder.Services.AddControllers();

builder.Services.AddOpenApi();

var app = builder.Build();

// Configure the HTTP request pipeline.
if (app.Environment.IsDevelopment())
{
    app.MapOpenApi();
}
appsettings.json
"profiles": {
  "http": {
    ..
    "launchBrowser": true,
    "launchUrl": "swagger",
    "applicationUrl": "http://localhost:5172",
   ..
    }
  },

Tuesday, May 13, 2025

Ado .Net

ADO.NET Tutorial with Inline SQL Examples

1. Introduction to ADO.NET

ADO.NET is a data access technology in .NET that allows communication with relational databases using managed providers such as SqlClient and OleDb.

2. SqlConnection and SqlDataReader Example (C#)

This example demonstrates reading data using inline SQL:


<script runat="server">
using System.Data.SqlClient;

SqlConnection cnn;
SqlCommand cmd;
SqlDataReader dr;

protected void Page_Load(object sender, EventArgs e)
{
    cnn = new SqlConnection("Integrated Security=SSPI;Initial Catalog=Northwind");
    cnn.Open();
    cmd = new SqlCommand("SELECT * FROM Categories", cnn);
    dr = cmd.ExecuteReader();
    while (dr.Read())
    {
        lstCategories.Items.Add(dr["CategoryName"].ToString());
    }
}
</script>

VB.NET Equivalent:


<script runat="server">
Imports System.Data.SqlClient

Dim cnn As SqlConnection
Dim cmd As SqlCommand
Dim dr As SqlDataReader

Protected Sub Page_Load(ByVal sender As Object, ByVal e As EventArgs)
    cnn = New SqlConnection("Integrated Security=SSPI;Initial Catalog=Northwind")
    cnn.Open()
    cmd = New SqlCommand("SELECT * FROM Categories", cnn)
    dr = cmd.ExecuteReader()
    While dr.Read()
        lstCategories.Items.Add(dr("CategoryName"))
    End While
End Sub
</script>

3. Inserting Records using Inline SQL


<script runat="server">
SqlCommand cmd;

protected void btnInsert_Click(object sender, EventArgs e)
{
    cmd = new SqlCommand("INSERT INTO Categories VALUES ('Condiments')", cnn);
    cmd.ExecuteNonQuery();
    MessageBox.Show("Record saved");
}
</script>

4. Inserting TextBox Values


<script runat="server">
protected void btnInsert_Click(object sender, EventArgs e)
{
    string strSql = "INSERT INTO Categories VALUES ('" + txtCategoryName.Text + "')";
    cmd = new SqlCommand(strSql, cnn);
    cmd.ExecuteNonQuery();
    MessageBox.Show("Record saved");
    txtCategoryName.Text = "";
    txtCategoryName.Focus();
}
</script>

5. Using DataAdapter and DataSet


<script runat="server">
using System.Data.SqlClient;

SqlConnection cnn;
SqlDataAdapter da;
DataSet ds = new DataSet();

protected void Page_Load(object sender, EventArgs e)
{
    cnn = new SqlConnection("Integrated Security=SSPI;Initial Catalog=Northwind");
    da = new SqlDataAdapter("SELECT * FROM Categories", cnn);
    da.Fill(ds, "Categories");
    dataGridView1.DataSource = ds.Tables["Categories"];
}
</script>

6. Working with Multiple DataTables


<script runat="server">
SqlDataAdapter da;
DataSet ds = new DataSet();

protected void Page_Load(object sender, EventArgs e)
{
    cnn = new SqlConnection("Integrated Security=SSPI;Initial Catalog=Northwind");

    da = new SqlDataAdapter("SELECT CategoryId, CategoryName FROM Categories", cnn);
    da.Fill(ds, "Cat");

    da = new SqlDataAdapter("SELECT ProductId, ProductName FROM Products", cnn);
    da.Fill(ds, "Prod");

    dataGrid1.DataSource = ds;
}
</script>

7. Creating AutoIncrement Column in DataTable


<script runat="server">
DataTable dt = new DataTable("Purchase");
DataColumn dc;
DataRow dr;

protected void Page_Load(object sender, EventArgs e)
{
    dc = new DataColumn("ProductID", typeof(int));
    dc.AutoIncrement = true;
    dc.AutoIncrementSeed = 100;
    dc.AutoIncrementStep = 1;
    dt.Columns.Add(dc);

    dc = new DataColumn("ProductName");
    dt.Columns.Add(dc);

    dc = new DataColumn("Price");
    dt.Columns.Add(dc);

    dr = dt.NewRow();
    dr["ProductName"] = "Microsoft Mouse";
    dr["Price"] = 400;
    dt.Rows.Add(dr);

    dgPurchase.DataSource = dt;
}
</script>

8. ComboBox DisplayMember Binding


<script runat="server">
SqlConnection cnn;
SqlDataAdapter da;
DataSet ds = new DataSet();

protected void Page_Load(object sender, EventArgs e)
{
    cnn = new SqlConnection("Integrated Security=SSPI;Initial Catalog=Northwind");
    da = new SqlDataAdapter("SELECT CategoryId, CategoryName FROM Categories", cnn);
    da.Fill(ds, "Cat");

    cboCategories.DataSource = ds.Tables["Cat"];
    cboCategories.DisplayMember = "CategoryName";
}
</script>

Sunday, October 28, 2018

React Native

React Native is a technology from Facebook to create native Android and iPhone applications. It uses the familiar JavaScript language and JSX syntax.

The easiest way to get started with React Native is to install Expo app in you mobile, going to https://snack.expo.io site and start coding. Setting up a development environment for React Native is a bit involved. We will take it up later.




>npm i -g create-react-native-app


>npm run android







Saturday, October 27, 2018

Node JS

Node is a JavaScript based Web Framework. Node's Non-blocking architecture makes it a very popular framework. V8 is the Virtual Machine of Node.


Node REPL
Once Node is installed, Node REPL can be invoked by typing node in the command prompt.



Typing tab tab in the prompt  displays  all Global command.

If you type a module name followed by tab tab it will display all the options pertaining to it.





Creating Http Server


const http = require('http');

const server = http.createServer((req, res) => {
  res.end('Hello World\n');
});

server.listen(4242, () => {
  console.log('Server is running...');
});


setTimeOut

setTimeout(
  () => {
    console.log('Hello after 4 seconds');
  },
  4 * 1000
);

Functions and Arguments
const consulting = who => {
  console.log(who + ' consulting');
};

setTimeout(consulting, 2 * 1000, 'Shalvin');

Thursday, October 25, 2018

Express JS

Hello Express


var express = require('express');

var app = express();

app.get('/', function (req, res) {
    res.send('Hello from Library app');
})

app.listen(3000, function () {
    console.log('listening ');
})


sendFile

In the previous example we just displayed some text. Now we are going to add an html file into the views folder and name it index.html.

var express = require('express');
var path = require('path');

var app = express();

app.get('/', function(req, res){
    res.sendFile(path.join(__dirname, 'views', 'index.html'));
})

app.listen(3000, function(){
    console.log('listening');
})

Wednesday, February 28, 2018

React State Collection of Objects


import React, { Component } from 'react';
import Person from './Person/Person';



class App extends Component {
  state = {
    person: [{name:'Shalvin P D', location: 'Kakkanad'},
    {name:'Shibin', location: 'Trivandrum'}
  ]
  }

  render() {
    return (
      <div>
        <h2>State eg</h2>

        
        <Person name = {this.state.person[0].name} 
        location = {this.state.person[0].location}></Person>

      <Person name = {this.state.person[1].name} 
        location = {this.state.person[1].location}></Person>
      </div>
    );
  }
}

export default App;

Friday, June 23, 2017

Angular Routing

app.module.ts

import { BrowserModule } from '@angular/platform-browser';
import { NgModule } from '@angular/core';

import { AppComponent } from './app.component';
import { ContactComponent } from './contact/contact.component';
import { DashboardComponent } from './dashboard/dashboard.component';
import {RouterModule, Routes} from '@angular/router';

@NgModule({
  declarations: [
    AppComponent,
    ContactComponent,
    DashboardComponent
  ],
  
   
  imports: [
    BrowserModule,
     RouterModule.forRoot([
       {path:'contact', component :ContactComponent},
       {path:'dashboard', component :DashboardComponent}
       ])
  ],
  providers: [],
  bootstrap: [AppComponent]
  
})
export class AppModule { }


app.component.ts

 <h1>{{title}}</h1>
 <a routerLink="/dashboard">Dashboard</a>
 <a routerLink="/contact">Contact</a>
   
  <router-outlet></router-outlet>