/// <summary> /// To generate the column names and column types /// </summary> /// <param name="m_QueryData"></param> /// <returns></returns> public DataTable GenerateColumnNameAndTypes(ClientAPI m_QueryData) { DataTable ret; try { ret = new DataTable(); ret.TableName = "testtable"; DataRow row; List<List<string>> ExecuteQueryData = new List<List<string>>(); ExecuteQueryData.Add(m_QueryData.IterateDataSet()); List<string> ColNames = m_QueryData.GetAllColumnNames(); List<System.Type> ColTypes = m_QueryData.GetAllColumnTypes(); //creating the column name column in the datagrid DataColumn m_ColumnName = new DataColumn(); m_ColumnName.ColumnName = "Column Name"; m_ColumnName.DataType = Type.GetType("System.String"); ret.Columns.Add(m_ColumnName); //creating the column types column in the datagrid DataColumn m_ColumnType = new DataColumn(); m_ColumnType.ColumnName = "Column Type"; m_ColumnType.DataType = Type.GetType("System.String"); ret.Columns.Add(m_ColumnType); //add the column names to the datatable for (int i = 0; i < ColNames.Count; i++) { row = ret.NewRow(); row["Column Name"] = ColNames[i].ToString(); row["Column Type"] = ColTypes[i].ToString(); ret.Rows.Add(row); } return ret; } catch (Exception ex) { MessageBox.Show(ex.Message); return new DataTable(); } }
public static void Main(string[] args) { DependencyInjection di = DependencyInjection.GetInstance(); di.SetConfig("config.xml"); Console.WriteLine("test begins"); ClientAPI m_TestObject = new ClientAPI(); m_TestObject.SetRootServer("http://localhost:8080/root"); m_TestObject.SetAuthHostAddress("http://localhost:8080/IComm"); m_TestObject.ConfigClient(); m_TestObject.ExecuteQuery("SELECT * FROM first_db.test_table", "mocktoken"); if (m_TestObject.CheckIfRowsReturned()) { List<string> string1 = m_TestObject.IterateDataSet(); List<string> ColNames = m_TestObject.GetAllColumnNames(); List<System.Type> ColTypes = m_TestObject.GetAllColumnTypes(); if (string1 == null) Console.WriteLine("the end"); Console.WriteLine(string1[1]); string1 = m_TestObject.IterateDataSet(); if (string1 == null) Console.WriteLine("the end"); Console.WriteLine(string1[1]); string1 = m_TestObject.IterateDataSet(); if (string1 == null) Console.WriteLine("the end"); Console.WriteLine(string1[1]); string1 = m_TestObject.IterateDataSet(); if (string1 == null) Console.WriteLine("the end"); Console.WriteLine(string1[1]); string1 = m_TestObject.IterateDataSet(); if (string1 == null) Console.WriteLine("the end"); Console.WriteLine(string1[1]); string1 = m_TestObject.IterateDataSet(); if (string1 == null) Console.WriteLine("the end"); Console.WriteLine(string1[1]); string1 = m_TestObject.IterateDataSet(); if (string1 == null) Console.WriteLine("the end"); Console.WriteLine(string1[1]); string1 = m_TestObject.IterateDataSet(); if (string1 == null) Console.WriteLine("the end"); Console.WriteLine(string1[1]); string1 = m_TestObject.IterateDataSet(); if (string1 == null) Console.WriteLine("the end"); Console.WriteLine(string1[1]); string1 = m_TestObject.IterateDataSet(); if (string1 == null) Console.WriteLine("the end"); Console.WriteLine(string1[1]); string1 = m_TestObject.IterateDataSet(); if (string1 == null) Console.WriteLine("the end"); } else { Console.WriteLine(" no row returned"); } }
public DataTable ConvertToDataTable(ClientAPI m_QueryData) { DataTable ret; try { ret = new DataTable(); ret.TableName = "testtable"; DataColumn column; DataRow row; List<List<string>> ExecuteQueryData = new List<List<string>>(); ExecuteQueryData.Add(m_QueryData.IterateDataSet()); List<string> ColNames = m_QueryData.GetAllColumnNames(); List<System.Type> ColTypes = m_QueryData.GetAllColumnTypes(); for (int i = 0; i < ColNames.Count; i++) { column = new DataColumn(); column.DataType = ColTypes[i]; column.ColumnName = ColNames[i]; column.ReadOnly = false; column.Unique = false; // Add the Column to the DataColumnCollection. ret.Columns.Add(column); } if (!(tb_RowsPerPage.Text == "")) { m_RowsPerPage = Convert.ToInt32(tb_RowsPerPage.Text); } else { m_RowsPerPage = 5; } for (int i = 0; i < m_RowsPerPage; i++) { List<string> tempList = m_QueryData.IterateDataSet(); ExecuteQueryData.Add(tempList); } for (int i = 0; i < m_RowsPerPage; i++) { List<string> rowdata = ExecuteQueryData[i]; row = ret.NewRow(); for (int j = 0; j < ColNames.Count; j++) { string temp = rowdata[j]; row[ColNames[j]] = Convert.ChangeType(temp, Type.GetType(ColTypes[j].ToString())); } ret.Rows.Add(row); } return ret; } catch (Exception ex) { MessageBox.Show(ex.Message); return new DataTable(); } }