private GenerateResponse GetFromData() { DataTable dtReturn = null; DataLayer.DataRunner objDR = null; var generateResponse = new GenerateResponse(); var myConnection = new SqlConnection(this.txtConnectionString1.Text); try { myConnection.Open(); var myCommand = new SqlCommand(this.txtConnectionString1.Text, myConnection); SqlDataAdapter adapter = new SqlDataAdapter(queryString, connection); DataSet customers = new DataSet(); adapter.Fill(customers, "Customers"); using (SqlDataReader oReader = myCommand.ExecuteReader()) { oReader.Read() while (oReader.Read()) { matchingPerson.firstName = oReader["FirstName"].ToString(); matchingPerson.lastName = oReader["LastName"].ToString(); } myConnection.Close(); } objDR = new DataLayer.DataRunner(this.txtConnectionString1.Text); dtReturn = objDR.ExecuteDataTableSQL(this.txtSQLSelect.Text); this.lblCount.Text = dtReturn.Rows.Count.ToString(); generateResponse.SQL = GetSQLFromDataText(dtReturn); generateResponse.QueryResult = dtReturn; } catch (System.Exception ex) { MessageBox.Show(ex.Message, "Problem", MessageBoxButtons.OK); } finally { myConnection.Close(); } //Save the connection string and the SQL this.LastConnectionString1 = this.txtConnectionString1.Text; this.LastSQL = this.txtSQLSelect.Text; //dtReturn.DefaultView.RowFilter = "Name = 'sourcing'"; return(generateResponse); }
private GenerateResponse GetFromData() { DataTable dtReturn = null; DataLayer.DataRunner objDR = null; var generateResponse = new GenerateResponse(); var myConnection = new SqlConnection(this.txtConnectionString1.Text); try { myConnection.Open(); var myCommand = new SqlCommand(this.txtConnectionString1.Text, myConnection); SqlDataAdapter adapter = new SqlDataAdapter(queryString, connection); DataSet customers = new DataSet(); adapter.Fill(customers, "Customers"); using (SqlDataReader oReader = myCommand.ExecuteReader()) { oReader.Read() while (oReader.Read()) { matchingPerson.firstName = oReader["FirstName"].ToString(); matchingPerson.lastName = oReader["LastName"].ToString(); } myConnection.Close(); } objDR = new DataLayer.DataRunner(this.txtConnectionString1.Text); dtReturn = objDR.ExecuteDataTableSQL(this.txtSQLSelect.Text); this.lblCount.Text = dtReturn.Rows.Count.ToString(); generateResponse.SQL = GetSQLFromDataText(dtReturn); generateResponse.QueryResult = dtReturn; } catch (System.Exception ex) { MessageBox.Show(ex.Message, "Problem", MessageBoxButtons.OK); } finally { myConnection.Close(); } //Save the connection string and the SQL this.LastConnectionString1 = this.txtConnectionString1.Text; this.LastSQL = this.txtSQLSelect.Text; //dtReturn.DefaultView.RowFilter = "Name = 'sourcing'"; return generateResponse; }