Node is saved as draft in My Content >> Draft
-
Execute Scalar in ADO.NET
about 9 years ago
about 9 years ago
In ADO.NET while writing codes we perform crud operations like Insert Update Delete.
While performing these crud operations we always use SqlCommand class with the ExecuteNonQuery method for doing it.
We need to know that ExecuteScalar method can also be used for this purpose.
This method returns a single value as the return type after the execution is done.
If your Result Set contains more than one columns or rows ,it will take value of first column and first row rest values will be ignored.
We can also use this method while performing crud operations.
List<SqlParameter> parameterList = new List<SqlParameter>();
parameterList.Add(new SqlParameter("@FirstName", user.FirstName));
parameterList.Add(new SqlParameter("@LastName", user.LastName));
parameterList.Add(new SqlParameter("@JobRoleID", user.JobRoleId));
parameterList.Add(new SqlParameter("@Email", user.Email));
parameterList.Add(new SqlParameter("@CompanyID", user.CompanyId));
parameterList.Add(new SqlParameter("@Password", user.Password));
parameterList.Add(new SqlParameter("@PasswordSalt", Guid.NewGuid().ToString()));
parameterList.Add(new SqlParameter("@AccessToken", accessToken));
parameterList.Add(new SqlParameter("@DeviceUUID", String.IsNullOrEmpty(user.DeviceId) ? String.Empty : user.DeviceId));
parameterList.Add(new SqlParameter("@DeviceType", String.IsNullOrEmpty(user.DeviceType) ? String.Empty : user.DeviceType));
parameterList.Add(new SqlParameter("@CreatedDate", System.DateTime.Now));
parameterList.Add(new SqlParameter("@IsDeleted", false));
parameterList.Add(new SqlParameter("@DeletedDate", System.DBNull.Value));
if (sqlConnection.State == ConnectionState.Closed) {
sqlConnection.Open();
}
result = Convert.ToInt32(BaseRepository.ExecuteScalar(ConnectionString, CommandType.StoredProcedure, "uspRegisterUser", parameterList.ToArray()));
List<SqlParameter> parameterList = new List<SqlParameter>();
parameterList.Add(new SqlParameter("@FirstName", user.FirstName));
parameterList.Add(new SqlParameter("@LastName", user.LastName));
parameterList.Add(new SqlParameter("@JobRoleID", user.JobRoleId));
parameterList.Add(new SqlParameter("@Email", user.Email));
parameterList.Add(new SqlParameter("@CompanyID", user.CompanyId));
parameterList.Add(new SqlParameter("@Password", user.Password));
parameterList.Add(new SqlParameter("@PasswordSalt", Guid.NewGuid().ToString()));
parameterList.Add(new SqlParameter("@AccessToken", accessToken));
parameterList.Add(new SqlParameter("@DeviceUUID", String.IsNullOrEmpty(user.DeviceId) ? String.Empty : user.DeviceId));
parameterList.Add(new SqlParameter("@DeviceType", String.IsNullOrEmpty(user.DeviceType) ? String.Empty : user.DeviceType));
parameterList.Add(new SqlParameter("@CreatedDate", System.DateTime.Now));
parameterList.Add(new SqlParameter("@IsDeleted", false));
parameterList.Add(new SqlParameter("@DeletedDate", System.DBNull.Value));
if (sqlConnection.State == ConnectionState.Closed) {
sqlConnection.Open();
}
result = Convert.ToInt32(BaseRepository.ExecuteScalar(ConnectionString, CommandType.StoredProcedure, "uspRegisterUser", parameterList.ToArray()));
0 Comment(s)