Home

C# Get Types From Object (SQL Fudge)

int x = 5;
string y = "Fred";
DateTime dt = DateTime.Now;

string[] ParamNames = { "@Int", "@String", "@DateTime" };
object[] ParamValues = { x, y, dt };

for (int i = 0; i < ParamNames.Length; i++)
{
    Type thisType = ParamValues[i].GetType();
    string typeFixed = thisType.Name;
    switch(typeFixed)
    {
        case "Int32":
            typeFixed = "int";
            break;
        case "String":
            typeFixed = "nvarchar(100)";
            break;
        case "DateTime":
            typeFixed = "datetime";
            break;
    }
    Console.WriteLine("declare " + ParamNames[i] + " " + thisType.Name);
}

Reader's Comments

Post Your Comment Posts/Links Rules

Name

Comment

Add a RELEVANT link (not required)

Upload an image (not required)

No uploaded image
Real person number
Please enter the above number below




Home
Admin Ren's Biking Blog