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
    
    
    
Name
Comment
Add a RELEVANT link (not required)
Upload an image (not required)
Uploading...
    Home