Home Python C Language C ++ HTML 5 CSS Javascript Java Kotlin SQL DJango Bootstrap React.js R C# PHP ASP.Net Numpy Dart Pandas Digital Marketing

ASP.NET ADO(ActiveX Data Objects for .NET) Objects Data Types:


In ADO.NET, data types play a crucial role in mapping between .NET types and database types. Here are some common .NET data types and their corresponding SQL Server data types when working with ADO.NET:

.NET Data Types and Corresponding SQL Server Data Types:

  1. System.Int32 (int) - Integer
  2. System.String (string) - VARCHAR, NVARCHAR, CHAR, NCHAR
  3. System.DateTime (DateTime) - DATETIME, SMALLDATETIME
  4. System.Decimal (decimal) - DECIMAL, NUMERIC
  5. System.Double (double) - FLOAT, REAL
  6. System.Single (float) - FLOAT, REAL
  7. System.Boolean (bool) - BIT
  8. System.Byte[] (byte[]) - VARBINARY, IMAGE
  9. System.Guid (Guid) - UNIQUEIDENTIFIER
  10. System.Object (object) - SQL_VARIANT

Example:

Let's see how you can use .NET data types with SqlCommand parameters:

using System.Data;
using System.Data.SqlClient;

// Example usage of .NET data types with SqlCommand parameters
SqlCommand command = new SqlCommand();
command.CommandText = "INSERT INTO Employees (Name, Age, JoiningDate, Salary) VALUES (@Name, @Age, @JoiningDate, @Salary)";
command.Parameters.Add("@Name", SqlDbType.NVarChar, 50).Value = "John Doe";
command.Parameters.Add("@Age", SqlDbType.Int).Value = 30;
command.Parameters.Add("@JoiningDate", SqlDbType.DateTime).Value = DateTime.Now;
command.Parameters.Add("@Salary", SqlDbType.Decimal).Value = 50000.00m;

In ADO.NET, data types play a crucial role in mapping between .NET types and database types. Here are some common .NET data types and their corresponding SQL Server data types when working with ADO.NET:

.NET Data Types and Corresponding SQL Server Data Types:

  1. System.Int32 (int) - Integer
  2. System.String (string) - VARCHAR, NVARCHAR, CHAR, NCHAR
  3. System.DateTime (DateTime) - DATETIME, SMALLDATETIME
  4. System.Decimal (decimal) - DECIMAL, NUMERIC
  5. System.Double (double) - FLOAT, REAL
  6. System.Single (float) - FLOAT, REAL
  7. System.Boolean (bool) - BIT
  8. System.Byte[] (byte[]) - VARBINARY, IMAGE
  9. System.Guid (Guid) - UNIQUEIDENTIFIER
  10. System.Object (object) - SQL_VARIANT

Example:

Let's see how you can use .NET data types with SqlCommand parameters:

csharp
using System.Data; using System.Data.SqlClient; // Example usage of .NET data types with SqlCommand parameters SqlCommand command = new SqlCommand(); command.CommandText = "INSERT INTO Employees (Name, Age, JoiningDate, Salary) VALUES (@Name, @Age, @JoiningDate, @Salary)"; command.Parameters.Add("@Name", SqlDbType.NVarChar, 50).Value = "John Doe"; command.Parameters.Add("@Age", SqlDbType.Int).Value = 30; command.Parameters.Add("@JoiningDate", SqlDbType.DateTime).Value = DateTime.Now; command.Parameters.Add("@Salary", SqlDbType.Decimal).Value = 50000.00m;

In this example:

Using appropriate .NET data types ensures proper type conversion and compatibility between your .NET application and the SQL Server database when working with ADO.NET.


Advertisement
Advertisement





Q3 Schools : India


Online Complier

HTML 5

Python

java

C++

C

JavaScript

Website Development

HTML

CSS

JavaScript

Python

SQL

Campus Learning

C

C#

java