Click here to Skip to main content
Click here to Skip to main content

Get LINQ GetCommand Parameters

, 5 Dec 2012
Rate this:
Please Sign up or sign in to vote.
Get LINQ GetCommand parameters.

Introduction

The article code returns GetCommand parameters for creating a Log In project.

Background

Create a Log in project afther Insert, Update, or Delete records.

Using the code

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Data.SqlClient;

namespace GetLinQueryLog
{
public class GetParameters
{
    public string CreateSqlLog(SqlCommand command)
    {
        string commandtext = command.CommandText;

        for (int i = command.Parameters.Count - 1; i >= 0; i--)
        {
            if (command.Parameters[i].SqlDbType == System.Data.SqlDbType.VarChar || 
                    command.Parameters[i].SqlDbType == System.Data.SqlDbType.UniqueIdentifier)
            {
                commandtext = commandtext.Replace(command.Parameters[i].ParameterName, 
                       "'" + command.Parameters[i].Value.ToString() + "'");
            }
            else if (command.Parameters[i].SqlDbType == System.Data.SqlDbType.NVarChar)
            {
                commandtext = commandtext.Replace(command.Parameters[i].ParameterName, 
                     " N'" + command.Parameters[i].Value.ToString() + "'");
            }
            else
            {
                commandtext = commandtext.Replace(
                  command.Parameters[i].ParameterName, command.Parameters[i].Value.ToString());
            }
        }
        return commandtext;
    }
}
}

License

This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

About the Author

moosa pourghafari

Iran (Islamic Republic Of) Iran (Islamic Republic Of)
No Biography provided

Comments and Discussions

 
-- There are no messages in this forum --
| Advertise | Privacy | Mobile
Web01 | 2.8.140721.1 | Last Updated 5 Dec 2012
Article Copyright 2012 by moosa pourghafari
Everything else Copyright © CodeProject, 1999-2014
Terms of Service
Layout: fixed | fluid