Skip to content
Loading
  • 0
    Hi Laxmidhar,
     
    Thanks for giving me response, Actualy what i want,  i will explane you breifly  
     
    featchin data from API like--
    public void CreateDynamicTable()
    {
    using (WebClient apiData = new WebClient())
    {
    var json = apiData.DownloadString("http://localhost:64086/api/us/Values/GetAllData");
    string valueOriginal = Convert.ToString(json);
    DataTable DtValue = ConvertJsonToDatatable(valueOriginal);
    string createTableScript = CreateTABLEQuery("TestTable", DtValue);
    DropIfExitTable("TestTable");
    ExuecuteSqlQuery(createTableScript);
    SqlCommand insert = CreateInsertQuery("TestTable", DtValue);
    BatchInsertUpdate(DtValue, insert, 10);
    }
    }
    using given data i create dynamic table like -
    public static string CreateTABLEQuery(string tableName, DataTable table)
    {
    string sqlsc;
    sqlsc = "CREATE TABLE " + tableName + "(";
    for (int i = 0; i < table.Columns.Count; i++)
    {
    sqlsc += "\n [" + table.Columns[i].ColumnName + "] ";
    string columnType = table.Columns[i].DataType.ToString();
    switch (columnType)
    {
    case "System.Int32":
    sqlsc += " int ";
    break;
    case "System.Int64":
    sqlsc += " bigint ";
    break;
    case "System.Int16":
    sqlsc += " smallint";
    break;
    case "System.Byte":
    sqlsc += " tinyint";
    break;
    case "System.Decimal":
    sqlsc += " decimal ";
    break;
    case "System.DateTime":
    sqlsc += " datetime ";
    break;
    case "System.Boolean":
    sqlsc += " bit ";
    break;
    case "System.String":
    default:
    sqlsc += string.Format(" nvarchar({0}) ", table.Columns[i].MaxLength == -1 ? "max" : table.Columns[i].MaxLength.ToString());
    break;
    }
    if (table.Columns[i].AutoIncrement)
    sqlsc += " IDENTITY(" + table.Columns[i].AutoIncrementSeed.ToString() + "," + table.Columns[i].AutoIncrementStep.ToString() + ") ";
    if (!table.Columns[i].AllowDBNull)
    sqlsc += " NOT NULL ";
    sqlsc += ",";
    }
    return sqlsc.Substring(0, sqlsc.Length - 1) + "\n)";
    }
     
    now using this table i want to crate dynamic model whenever API will be change automatic model will be change, is it possible?
    0
  • Laxmidhar Sahoo
    0
    hi
    Thanks
    Whether the webclient  respence or not if yes so
    Can you show me the data structure that the webclient respence.
    0
  • Siddharth Gajbhiye
    0
    Hello Rahul
     
     
    Please refer the below link
     
    https://stackoverflow.com/questions/29676230/how-to-use-a-dynamic-model-to-create-a-dynamic-table
     
    it might slove your problem
     
     
    Thanku 
    0