Click here to Skip to main content
13,290,261 members (51,806 online)
Click here to Skip to main content
Add your own
alternative version

Tagged as

Stats

4.8K views
5 bookmarked
Posted 5 Dec 2012

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)

Share

About the Author

moosa pourghafari
Iran (Islamic Republic of) Iran (Islamic Republic of)
No Biography provided

You may also be interested in...

Comments and Discussions

 
-- There are no messages in this forum --
Permalink | Advertise | Privacy | Terms of Use | Mobile
Web03 | 2.8.171207.1 | Last Updated 5 Dec 2012
Article Copyright 2012 by moosa pourghafari
Everything else Copyright © CodeProject, 1999-2017
Layout: fixed | fluid