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:
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:
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 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.