Tuesday, February 7, 2023
Learning Code
  • Home
  • JavaScript
  • Java
  • Python
  • Swift
  • C++
  • C#
No Result
View All Result
  • Home
  • JavaScript
  • Java
  • Python
  • Swift
  • C++
  • C#
No Result
View All Result
Learning Code
No Result
View All Result
Home C#

C# – Using Table Valued Parameter – Csharp Star

learningcode_x1mckf by learningcode_x1mckf
September 4, 2022
in C#
0
C# – Knapsack Problem – Csharp Star
74
SHARES
1.2k
VIEWS
Share on FacebookShare on Twitter


You might also like

C# – Floyd–Warshall Algorithm – Csharp Star

C# – Brute-Force Algorithm – Csharp Star

C# – Bellman–Ford Algorithm – Csharp Star

On this article, we’ll be taught:

  • What’s Desk Valued Parameter?
  • The way to cross Desk Valued Parameter from C#?
  • Benefits of utilizing Desk Valued Parameter?

 

What’s Desk Valued Parameter?

Desk Valued Parameters are used to cross a number of rows of knowledge from a .internet/consumer utility to SQL Server with out a number of spherical journeys. we will cross a number of rows of a desk to a saved process.
 

The way to create a Desk Valued Parameter and cross it from C#?

 

Step 1: Create a Desk in SQL server

On this instance, we’ll create a SALESPERSON desk.

CREATE TABLE SALESPERSON
(
      ID INT NOT NULL, 
      Title VARCHAR(MAX), 
      IsActive VARCHAR(10),
      PRIMARY KEY (ID)
)

 

Step 2: Create a Desk Valued Parameter in SQL server

CREATE TYPE dbo.SALESPERSONTYPE AS TABLE 
(
      ID INT NOT NULL, 
      Title VARCHAR(MAX), 
      IsActive VARCHAR(10),
      PRIMARY KEY (ID)
)

 

Step 3: Create a saved process to Insert data to SALESPERSON desk in DB

CREATE PROCEDURE InsertData
(@SALESPERSONTYPE  AS dbo.SALESPERSONTYPE READONLY)
AS
BEGIN
      INSERT INTO SALESPERSON(ID ,Title ,IsActive)
      SELECT ID, Title, IsActive FROM @SALESPERSONTYPE  
END

 

Step 4:Create a DataTable from ADO.internet identical as your Desk Valued Parameter

 

static DataTable CreateTable()

    DataTable dt = new DataTable();
    dt.Columns.Add("ID", typeof(Int32));
    dt.Columns.Add("Title", typeof(string));
    dt.Columns.Add("IsActive", typeof(string));
    return dt;

 

Step 5: Move DataTable to Saved Process as a parameter

//Create Desk
DataTable salepersonTable = CreateTable(); 

// Add New Rowto desk
salepersonTable.Rows.Add(1, "Lisa","Sure");
salepersonTable.Rows.Add(2, "Jennifer", "No");
salepersonTable.Rows.Add(3, "Tina", "Sure");
salepersonTable.Rows.Add(4, "John", "Sure");
salepersonTable.Rows.Add(5, "Ryan", "Sure");
 
SqlConnection connection = new SqlConnection("Knowledge Supply= DatabaseName;Preliminary Catalog=csharpstar;Person
Id=cs;Password=cs123;");
connection.Open();
SqlCommand cmd = new SqlCommand("InsertData", connection);
cmd.CommandType = CommandType.StoredProcedure;

//Move desk Valued parameter to Retailer Process
SqlParameter sqlParam = cmd.Parameters.AddWithValue("SALESPERSONTYPE", salepersonTable);
sqlParam.SqlDbType = SqlDbType.Structured; 
cmd.ExecuteNonQuery();
connection.Shut();
Console.Write("Knowledge Inserted Efficiently.");

 

Benefits of utilizing Desk Valued Parameter?

  • You’ll be able to keep away from a number of spherical journeys between consumer utility and Database
  • Efficiency will probably be a lot better since you may insert a number of data as soon as into the desk

 
Thanks for visiting !

© 2017, Csharp Star. All rights reserved.

Associated



Source link

Share30Tweet19
learningcode_x1mckf

learningcode_x1mckf

Recommended For You

C# – Floyd–Warshall Algorithm – Csharp Star

by learningcode_x1mckf
September 4, 2022
0
C# – Knapsack Problem – Csharp Star

On this article, we'll be taught C# implementation of Floyd–Warshall Algorithm for figuring out the shortest paths in a weighted graph with optimistic or destructive edge weights utilizing System;...

Read more

C# – Brute-Force Algorithm – Csharp Star

by learningcode_x1mckf
September 4, 2022
0
C# – Knapsack Problem – Csharp Star

On this article, we are going to study C# implementation of Brute-Power Algorithm.Brute-force search or exhaustive search, often known as generate and take a look at, is a...

Read more

C# – Bellman–Ford Algorithm – Csharp Star

by learningcode_x1mckf
September 4, 2022
0
C# – Knapsack Problem – Csharp Star

On this article, we'll be taught C# implementation of Bellman–Ford Algorithm for figuring out the shortest paths from a single supply vertex to the entire different vertices in...

Read more

C# – Knapsack Problem – Csharp Star

by learningcode_x1mckf
September 4, 2022
0
C# – Knapsack Problem – Csharp Star

On this article, we'll write C# implementation for Knapsack drawback utilizing System; utilizing System.Collections.Generic; utilizing System.Linq; utilizing System.Textual content; utilizing System.Diagnostics; namespace KnapsackAlgo {     class KnapsackAlgorithm              public static...

Read more

C#11 Will Support Raw String Literals

by learningcode_x1mckf
September 4, 2022
0
C#11 Will Support Raw String Literals

Particulars of what Microsoft is including to C# 11 have been launched, with modifications concentrating on higher efficiency together with new language options together with uncooked string literals...

Read more
Next Post
Theo’s Java Club still looking for new owner a year after closing

Theo's Java Club still looking for new owner a year after closing

Leave a Reply Cancel reply

Your email address will not be published. Required fields are marked *

Related News

JavaScript In Space – James Webb Telescope

JavaScript In Space – James Webb Telescope

September 7, 2022
COBOL programming skills gap thwarts modernization to Java

COBOL programming skills gap thwarts modernization to Java

September 11, 2022
PlanetScale introduces serverless driver for JavaScript: Databases are moving to the edge

PlanetScale introduces serverless driver for JavaScript: Databases are moving to the edge

September 8, 2022

Browse by Category

  • C#
  • C++
  • Java
  • JavaScript
  • Python
  • Swift

RECENT POSTS

  • JobRunr, the Java Scheduler Library, Released Version 6.0 – InfoQ.com
  • An Introduction to Lodash and Its Benefits for JavaScript Developers – MUO – MakeUseOf
  • "Used properly, Python is not slower than C++" – eFinancialCareers (US)

CATEGORIES

  • C#
  • C++
  • Java
  • JavaScript
  • Python
  • Swift

© 2022 Copyright Learning Code

No Result
View All Result
  • Home
  • JavaScript
  • Java
  • Python
  • Swift
  • C++
  • C#

© 2022 Copyright Learning Code

Are you sure want to unlock this post?
Unlock left : 0
Are you sure want to cancel subscription?