public static System.Data.DataSet ExecuteDatasetQueryOnDB(string sSQL, string sConnectionString) { System.Data.Odbc.OdbcDataAdapter QDataAdapter = null; DataSet QDataSet = null; try { QDataSet = new DataSet(); QDataAdapter = new System.Data.Odbc.OdbcDataAdapter(sSQL, sConnectionString); QDataAdapter.Fill(QDataSet); return(QDataSet); } finally { if (QDataSet != null) { QDataSet.Dispose(); } QDataSet = null; if (QDataAdapter != null) { QDataAdapter.Dispose(); } QDataAdapter = null; } }
// UPLOAD BUTTON HANDLER ------------------------------------------------------------------------------------------------------- protected void uploadbutton_Click(object sender, EventArgs e) { // Get button ID Button getbuttonID = (Button)sender; string id = getbuttonID.ID.Replace("_button", ""); // Use button ID to find similarly named upload control ID FileUpload uploadcontrol = (FileUpload)Form.FindControl(id); // Only upload if control has file selected if (uploadcontrol.HasFile) { // Add upload path String savePath = @"c:\temp\"; // Retrieve filename from upload control String fileName = uploadcontrol.FileName; // Save data to web server uploadcontrol.SaveAs(savePath + fileName); // Fill GridView // Establish text driver connection System.Data.Odbc.OdbcConnection csv_connection; System.Data.Odbc.OdbcDataAdapter csv_adapter; // Create temporary data table to store CSV data DataTable csv_data = new DataTable(); // Create connection string and execute connection to CSV string csv_connectionString = @"Driver={Microsoft Text Driver (*.txt; *.csv)};Dbq=" + savePath + ";"; csv_connection = new System.Data.Odbc.OdbcConnection(csv_connectionString); // Fill adapter with SELECT * query from CSV csv_adapter = new System.Data.Odbc.OdbcDataAdapter("select * from [" + fileName + "]", csv_connection); csv_adapter.Fill(csv_data); // Close CSV connection csv_connection.Close(); // Find GridView and fill GridView filedata = (GridView)Form.FindControl(id + "_table"); filedata.DataSource = csv_data; filedata.DataBind(); // SESSION MODIFICATION // DataSet session_datanew = new DataSet(); session_datanew.Tables.Add(csv_data); session_datanew.DataSetName = "PCADATA"; Registry.Registry registry = Registry.Registry.getRegistry(Session); registry.registerDataset(session_datanew); Analysis.ParameterStream stream = Analysis.ParameterStream.getStream(Session); stream.set("dataSetName", "PCADATA"); //----------------------// } }
public IActionResult OnPostExecuteQuery(string query, string connections) { CloudQuery.Models.QueryResult qr = new Models.QueryResult(); qr.Message = "Query execution incomplete"; // get the connectionObject var conn = Newtonsoft.Json.JsonConvert.DeserializeObject <CloudQuery.Models.DBConnection>(connections); if (conn.DBName.StartsWith("#")) { PopulateConnectionDataFromMount(conn); } string connectionString = string.Format("Server=tcp:{0}.database.windows.net,1433;Database={1};Uid={2}@{0};Pwd={3};Encrypt=yes;TrustServerCertificate=no;Connection Timeout=30;KeyStoreAuthentication=KeyVaultManagedIdentity", conn.DBServer, conn.DBName, conn.Username, conn.Password); if ("true".CompareTo(System.Environment.GetEnvironmentVariable("MSI")) == 0) { connectionString = string.Format("Server=tcp:{0}.database.windows.net,1433;Database={1};Uid={2}@{0};Authentication=ActiveDirectoryMsi;Encrypt=yes;TrustServerCertificate=no;Connection Timeout=30", conn.DBServer, conn.DBName, conn.Username, conn.Password); } else if ("true".CompareTo(System.Environment.GetEnvironmentVariable("ODBC_ALWAYSENCRYPTED")) == 0) { connectionString = string.Format("Server=tcp:{0}.database.windows.net,1433;Database={1};Uid={2};Authentication=ActiveDirectoryMsi;Encrypt=yes;TrustServerCertificate=no;Connection Timeout=30;ColumnEncryption=Enabled;KeyStoreAuthentication=KeyVaultManagedIdentity;KeyStorePrincipalId={2}", conn.DBServer, conn.DBName, conn.Username, conn.Password); } connectionString = "Driver={ODBC Driver 17 for SQL Server};" + connectionString; Console.WriteLine($"ConnectionString: {connectionString}"); try { int rowsReturned = 0; System.Data.DataSet ds; using (System.Data.Odbc.OdbcDataAdapter adapter = new System.Data.Odbc.OdbcDataAdapter(query, connectionString)) { ds = new System.Data.DataSet(); rowsReturned = adapter.Fill(ds); } // only selects will return a Table of results; if (ds.Tables.Count == 0) // not a table { qr.Message = "Query completed successfully"; } else if (ds.Tables.Count == 1) { // return the results qr.Results = ds.Tables[0]; // return rowsAffected for message qr.Message = string.Format("{0} rows returned.", rowsReturned); } } catch (Exception ex) { qr.Exception = ex; qr.Message = ex.Message; } ViewData["results"] = qr; return(View("Index")); }
public static DbDataAdapter CreateDataAdapter(DbConnection connection) { DbDataAdapter adapter; //we can't construct an adapter directly //So let's run around the block 3 times, before potentially crashing if (connection is System.Data.SqlClient.SqlConnection) { adapter = new System.Data.SqlClient.SqlDataAdapter(); } else if (connection is System.Data.OleDb.OleDbConnection) { adapter = new System.Data.OleDb.OleDbDataAdapter(); } else if (connection is System.Data.Odbc.OdbcConnection) { adapter = new System.Data.Odbc.OdbcDataAdapter(); } //TODO: Add more DbConnection kinds as they become invented else { string fullName = connection.GetType().FullName; adapter = DbProviderFactories.GetFactory(fullName.Substring(0, fullName.LastIndexOf("."))).CreateDataAdapter(); } return(adapter); }
private void btLoad_Click(object sender, System.EventArgs e) { try { System.Data.DataSet dataset = new System.Data.DataSet(); using (System.Data.Odbc.OdbcDataAdapter adapter = new System.Data.Odbc.OdbcDataAdapter(txtSqlQuery.Text, txtConnectionString.Text)) { adapter.Fill(dataset); } //Debug Trace dataset.Tables[0].RowDeleted += new System.Data.DataRowChangeEventHandler(frmSample9_RowDeleted); dataset.Tables[0].RowChanged += new System.Data.DataRowChangeEventHandler(frmSample9_RowChanged); dataset.Tables[0].ColumnChanged += new System.Data.DataColumnChangeEventHandler(frmSample9_ColumnChanged); lbRowsNumber.Text = "Rows: " + dataset.Tables[0].Rows.Count; dataGrid.FixedColumns = 1; dataGrid.FixedRows = 1; dataGrid.Columns.Clear(); dataGrid.DataSource = dataset.Tables[0].DefaultView; dataGrid.Columns[0].AutoSizeMode = SourceGrid.AutoSizeMode.MinimumSize; dataGrid.Columns[0].Width = 20; dataGrid.Columns.AutoSizeView(); chkAllowNew.Checked = dataGrid.DataSource.AllowNew; chkEdit.Checked = dataGrid.DataSource.AllowEdit; } catch (Exception err) { DevAge.Windows.Forms.ErrorDialog.Show(this, err, "Error loading dataset"); } }
public static DbDataAdapter CreateDataAdapter(DbCommand dbCommand, DbConnection connection) { DbDataAdapter adapter; //we can't construct an adapter directly //So let's run around the block 3 times, before potentially crashing if (connection is System.Data.SqlClient.SqlConnection) { adapter = new System.Data.SqlClient.SqlDataAdapter(dbCommand.CommandText, connection as SqlConnection); } else if (connection is System.Data.OleDb.OleDbConnection) { adapter = new System.Data.OleDb.OleDbDataAdapter(dbCommand.CommandText, connection as System.Data.OleDb.OleDbConnection); } else if (connection is System.Data.Odbc.OdbcConnection) { adapter = new System.Data.Odbc.OdbcDataAdapter(dbCommand.CommandText, connection as System.Data.Odbc.OdbcConnection); } else if (connection is System.Data.SqlServerCe.SqlCeConnection) { adapter = new System.Data.SqlServerCe.SqlCeDataAdapter(dbCommand.CommandText, connection as System.Data.SqlServerCe.SqlCeConnection); } //TODO: Add more DbConnection kinds as they become invented else { throw new Exception("[CreateDataAdapter] Unknown DbConnection type: " + connection.GetType().FullName); } return(adapter); }
public DataTable ExecuteSelectQuery(string sQuery) { string sFuncName = "ExecuteSelectQuery()"; string sConstr = ConfigurationManager.ConnectionStrings["adapterConnection"].ToString(); System.Data.Odbc.OdbcConnection oCon = new System.Data.Odbc.OdbcConnection(sConstr); System.Data.Odbc.OdbcCommand oCmd = new System.Data.Odbc.OdbcCommand(); DataSet oDs = new DataSet(); try { oCon.Open(); oCmd.CommandType = CommandType.Text; oCmd.CommandText = sQuery; oCmd.Connection = oCon; oCmd.CommandTimeout = 120; System.Data.Odbc.OdbcDataAdapter da = new System.Data.Odbc.OdbcDataAdapter(oCmd); da.Fill(oDs); } catch (Exception ex) { if (p_iDebugMode == DEBUG_ON) { oLog.WriteToLogFile_Debug("Completed with Error", sFuncName); } oCon.Dispose(); throw new Exception(ex.Message); } return(oDs.Tables[0]); }
public DataTable ExecuteSQLQuery(string sQuery, string sCompanyCode, System.Data.Odbc.OdbcParameter[] param) { string sFuncName = "ExecuteSQLQuery()"; string sConstr = ConfigurationManager.ConnectionStrings["DBSSG"].ToString(); string[] sArray = sConstr.Split(';'); string sSplitCompany = sConstr.Split(';').Last(); string sSplit1 = sSplitCompany.Split('=').First(); string sCompanyGenerate = sSplit1 + "=" + sCompanyCode; sConstr = sArray[0] + ";" + sArray[1] + ";" + sArray[2] + ";" + sArray[3] + ";" + sCompanyGenerate; if (p_iDebugMode == DEBUG_ON) { oLog.WriteToLogFile_Debug("Connection String : " + sConstr, sFuncName); } System.Data.Odbc.OdbcConnection oCon = new System.Data.Odbc.OdbcConnection(sConstr); System.Data.Odbc.OdbcCommand oCmd = new System.Data.Odbc.OdbcCommand(); DataSet oDs = new DataSet(); try { oCon.Open(); oCmd.CommandType = CommandType.Text; oCmd.CommandText = sQuery; if (p_iDebugMode == DEBUG_ON) { oLog.WriteToLogFile_Debug("SQL Query : " + sQuery, sFuncName); } if (p_iDebugMode == DEBUG_ON) { oLog.WriteToLogFile_Debug("Before adding Parameters", sFuncName); } foreach (var item in param) { oCmd.Parameters.Add(item); } //oCmd.Parameters.Add((param); if (p_iDebugMode == DEBUG_ON) { oLog.WriteToLogFile_Debug("After adding parameters", sFuncName); } oCmd.Connection = oCon; oCmd.CommandTimeout = 120; System.Data.Odbc.OdbcDataAdapter da = new System.Data.Odbc.OdbcDataAdapter(oCmd); da.Fill(oDs); } catch (Exception ex) { if (p_iDebugMode == DEBUG_ON) { oLog.WriteToLogFile_Debug("Completed With Error", sFuncName); } oCon.Dispose(); throw new Exception(ex.Message); } return(oDs.Tables[0]); }
public bool MaterializaAvaliacao(cAvaliacao obj) { string sql; try { sql = "SELECT a.id as id, "; sql += " a.data as data, "; sql += " a.idade as idade, "; sql += " a.peso as peso, "; sql += " a.altura as altura, "; sql += " a.nivel_atividade as nivel_atividade, "; sql += " a.gordura as gordura, "; sql += " a.vo2 as vo2, "; sql += " a.desc_atividade as desc_atividade, "; sql += " a.observacoes as observacoes, "; sql += " a.fc_max_obtida as fc_max_obtida, "; sql += " a.fc_min_obtida as fc_min_obtida, "; sql += " a.fc_media_obtida as fc_media_obtida, "; sql += " a.tmb as tmb, "; sql += " a.fc_basal as fc_basal, "; sql += " p.nome as x_nome "; sql += " FROM avaliacao AS a LEFT JOIN pessoa AS p ON p.id = a.id_pessoa WHERE a.id = " + obj.id.ToString(); sqlConn = new System.Data.Odbc.OdbcConnection(connString); sqlConn.Open(); sqlCmd = new System.Data.Odbc.OdbcCommand(sql, sqlConn); sqlAdapter = new System.Data.Odbc.OdbcDataAdapter(); sqlAdapter.SelectCommand = sqlCmd; sqlDataSet = new System.Data.DataSet(); sqlAdapter.Fill(sqlDataSet); System.Data.DataTable dt = sqlDataSet.Tables[0]; if (dt.Rows.Count > 0) { System.Data.DataRow linha = dt.Rows[0]; obj.id = int.Parse(linha["id"].ToString()); obj.idade = int.Parse(linha["idade"].ToString()); obj.peso = float.Parse(linha["peso"].ToString()); obj.data_hora = DateTime.Parse(linha["data"].ToString()); obj.x_nome = linha["x_nome"].ToString(); obj.altura = float.Parse(linha["altura"].ToString()); obj.nivel_atividade = int.Parse(linha["altura"].ToString()); } sqlConn.Close(); return(true); } catch (Exception Ex) { return(false); } }
// Code changes done here with Param public DataTable ExecuteSelectQuery(string sQuery, System.Data.Odbc.OdbcParameter[] param) { string sFuncName = "ExecuteSelectQuery()"; if (p_iDebugMode == DEBUG_ON) { oLog.WriteToLogFile_Debug("Starting Function", sFuncName); } string sConstr = ConfigurationManager.ConnectionStrings["adapterConnection"].ToString(); System.Data.Odbc.OdbcConnection oCon = new System.Data.Odbc.OdbcConnection(sConstr); System.Data.Odbc.OdbcCommand oCmd = new System.Data.Odbc.OdbcCommand(); DataSet oDs = new DataSet(); try { oCon.Open(); oCmd.CommandType = CommandType.Text; oCmd.CommandText = sQuery; if (p_iDebugMode == DEBUG_ON) { oLog.WriteToLogFile_Debug("SQL Query : " + sQuery, sFuncName); } if (p_iDebugMode == DEBUG_ON) { oLog.WriteToLogFile_Debug("Before adding Parameters", sFuncName); } foreach (var item in param) { oCmd.Parameters.Add(item); } //oCmd.Parameters.Add((param); if (p_iDebugMode == DEBUG_ON) { oLog.WriteToLogFile_Debug("After adding parameters", sFuncName); } oCmd.Connection = oCon; oCmd.CommandTimeout = 120; System.Data.Odbc.OdbcDataAdapter da = new System.Data.Odbc.OdbcDataAdapter(oCmd); da.Fill(oDs); if (p_iDebugMode == DEBUG_ON) { oLog.WriteToLogFile_Debug("Completed with Success", sFuncName); } } catch (Exception ex) { if (p_iDebugMode == DEBUG_ON) { oLog.WriteToLogFile_Debug("Completed with Error", sFuncName); } oCon.Dispose(); throw new Exception(ex.Message); } return(oDs.Tables[0]); }
/// <summary> /// DBF数据导入 /// </summary> /// <returns>成功返回1 失败返回-1</returns> protected int ImportDBF(string dataFilePath) { if (this.ds != null) { this.ds.Clear(); } else { this.ds = new DataSet(); } try { Neusoft.FrameWork.WinForms.Classes.Function.ShowWaitForm(Neusoft.FrameWork.Management.Language.Msg("正在读入数据 请稍候..")); Application.DoEvents(); string sourcePathName = dataFilePath.Substring(0, dataFilePath.LastIndexOf("\\")); string sourceFileName = dataFilePath.Substring(dataFilePath.LastIndexOf("\\") + 1, dataFilePath.Length - dataFilePath.LastIndexOf("\\") - 1); this.odbcDataAdapter = new System.Data.Odbc.OdbcDataAdapter(); this.odbcDataCommand = new System.Data.Odbc.OdbcCommand(); this.odbcDataConnection = new System.Data.Odbc.OdbcConnection(); this.odbcDataConnection.ConnectionString = "MaxBufferSize=2048;DSN=dBASE Files;PageTimeout=5;DefaultDir=" + sourcePathName + "\\;DBQ=" + sourcePathName + "\\;DriverId=" + "533"; this.odbcDataCommand.Connection = this.odbcDataConnection; this.odbcDataAdapter.SelectCommand = this.odbcDataCommand; this.odbcDataCommand.CommandText = "SELECT * FROM " + sourceFileName; this.odbcDataAdapter.Fill(this.ds); if (this.ds.Tables.Count <= 0) { MessageBox.Show(Neusoft.FrameWork.Management.Language.Msg("无数据")); return(1); } int column = this.ds.Tables[0].Columns.Count; int row = this.ds.Tables[0].Rows.Count; this.lbDataInfo.Text = "该数据文件共有" + column.ToString() + "列。共有" + row.ToString() + "条记录。"; this.neuSpread1_Sheet1.DataSource = this.ds; this.rs = DialogResult.OK; Neusoft.FrameWork.WinForms.Classes.Function.HideWaitForm(); } catch (Exception ee) { MessageBox.Show(ee.Message.ToString()); return(-1); } return(1); }
public static System.Data.DataSet GetDataSet(System.Data.Odbc.OdbcConnection conn, string sql) { try{ var command = new System.Data.Odbc.OdbcCommand(sql, conn); var adapter = new System.Data.Odbc.OdbcDataAdapter(command); var set = new System.Data.DataSet(); adapter.Fill(set); return(set); }catch (Exception ex) { throw ex; }finally{ } }
public int ListarAvaliacoes(cAvaliacao obj, ref string[][] array) { string sql; try { sql = "SELECT a.id as id, a.data as data, p.nome as nome FROM avaliacao AS a LEFT JOIN pessoa AS p ON p.id = a.id_pessoa WHERE 1 = 1 "; if (obj.x_nome != String.Empty) { sql += " AND p.nome LIKE '%" + obj.x_nome + "%'"; } sqlConn = new System.Data.Odbc.OdbcConnection(connString); sqlConn.Open(); sqlCmd = new System.Data.Odbc.OdbcCommand(sql, sqlConn); sqlAdapter = new System.Data.Odbc.OdbcDataAdapter(); sqlAdapter.SelectCommand = sqlCmd; sqlDataSet = new System.Data.DataSet(); sqlAdapter.Fill(sqlDataSet); System.Data.DataTable dt = sqlDataSet.Tables[0]; if (dt.Rows.Count > 0) { array = new string[dt.Rows.Count][]; int i = 0; foreach (System.Data.DataRow row in dt.Rows) { array[i] = new string[3]; array[i][0] = row[0].ToString(); array[i][1] = row[1].ToString(); array[i][2] = row[2].ToString(); i++; } } sqlConn.Close(); return(dt.Rows.Count); } catch (Exception Ex) { return(-1); } }
public DataTable GetDataTable(string SQLstr) { DataTable dt = new DataTable(); System.Data.Odbc.OdbcDataAdapter da; System.Data.Odbc.OdbcCommand cmd = new System.Data.Odbc.OdbcCommand(SQLstr, this.mCon); da = new System.Data.Odbc.OdbcDataAdapter(cmd); da.Fill(dt); this.mCon.Close(); cmd.Dispose(); return(dt); }
public int ListarPessoas(cPessoa obj, ref string [][] array) { string sql; try{ if (obj.sNome == String.Empty) { sql = "SELECT ID, nome FROM pessoa"; } else { sql = "SELECT ID, nome FROM pessoa WHERE nome like '%" + obj.sNome + "%'"; } sqlConn = new System.Data.Odbc.OdbcConnection(connString); sqlConn.Open(); sqlCmd = new System.Data.Odbc.OdbcCommand(sql, sqlConn); sqlAdapter = new System.Data.Odbc.OdbcDataAdapter(); sqlAdapter.SelectCommand = sqlCmd; sqlDataSet = new System.Data.DataSet(); sqlAdapter.Fill(sqlDataSet, "pessoa"); System.Data.DataTable dt = sqlDataSet.Tables["pessoa"]; if (dt.Rows.Count > 0) { array = new string[dt.Rows.Count][]; int i = 0; foreach (System.Data.DataRow row in dt.Rows) { array[i] = new string[2]; array[i][0] = row[0].ToString(); array[i][1] = row[1].ToString(); i++; } } sqlConn.Close(); return(dt.Rows.Count); }catch (Exception Ex) { return(-1); } }
public DataSet ConnectCSV(string filetable, bool bFill) { DataSet ds = new DataSet(); try { // You can get connected to driver either by using DSN or connection string // Create a connection string as below, if you want to use DSN less connection. The DBQ attribute sets the path of directory which contains CSV files string strConnString = "Driver={Microsoft Text Driver (*.txt; *.csv)};Dbq=" + txtCSVFolderPath.Text.Trim() + ";Extensions=asc,csv,tab,txt;Persist Security Info=False"; string sql_select; System.Data.Odbc.OdbcConnection conn; //Create connection to CSV file conn = new System.Data.Odbc.OdbcConnection(strConnString.Trim()); // For creating a connection using DSN, use following line //conn = new System.Data.Odbc.OdbcConnection(DSN="MyDSN"); //Open the connection conn.Open(); //Fetch records from CSV sql_select = "select * from [" + filetable + "]"; obj_oledb_da = new System.Data.Odbc.OdbcDataAdapter(sql_select, conn); //Fill dataset with the records from CSV file obj_oledb_da.Fill(ds, "Customers"); if (bFill) { //Set the datagrid properties dGridCSVdata.DataSource = ds; dGridCSVdata.DataMember = "Customers"; //Close Connection to CSV file } conn.Close(); } catch (Exception exe) //Error { MMSUtility.LogFile(exe.Message, "", "ConnectCSV", exe.LineNumber(), "PrintLetterDialog"); MessageBox.Show(exe.Message); } return ds; }
protected override DataTable InternalGetSampleData(SchemaNode tableOrView, RowLimitClause rowLimitClause, IdentifierQuoting identifierQuoting, out bool isError) { try { var sql = GetSampleSql(rowLimitClause, tableOrView.GetRef(identifierQuoting, false), 200); var adapter = new System.Data.Odbc.OdbcDataAdapter(sql, ProviderString); adapter.SelectCommand.CommandTimeout = 30; var result = new DataTable(); adapter.Fill(0, 200, result); isError = false; return(result); } catch (Exception ex) { ErrorTable.Rows[0][0] = ex.Message; isError = true; return(ErrorTable); } }
public static System.Data.DataTable GetDataTable(string strFileName) { string fullPath = System.IO.Path.GetFullPath(strFileName); string fileLocation = System.IO.Path.GetDirectoryName(fullPath); string tableName = System.IO.Path.GetFileName(fullPath); string connTemplate = "Driver={0}; Dbq={1}; Extensions=asc,csv,tab,txt;Persist Security Info=False"; string connString = string.Format(connTemplate, @"{Microsoft Text Driver (*.txt; *.csv)}", fileLocation); System.Data.Odbc.OdbcConnection conn = new System.Data.Odbc.OdbcConnection(connString); conn.Open(); string strQuery = string.Format("SELECT * FROM [{0}]", tableName); System.Data.Odbc.OdbcDataAdapter adapter = new System.Data.Odbc.OdbcDataAdapter(strQuery, conn); System.Data.DataSet ds = new System.Data.DataSet(); adapter.Fill(ds); return(ds.Tables[0]); }
public static DataSet ImportCSVFile(string path) { // TODO: method assumes path exists. string directory = Path.GetDirectoryName(path); string filename = Path.GetFileName(path); CreateIniFile(path); System.Data.Odbc.OdbcConnection odbcconn = null; DataSet taxds = new DataSet(); System.Data.Odbc.OdbcDataAdapter odbcda; try { // string connectionString = "Driver={Microsoft Text Driver (*.txt;*.csv)};Dbq=" // + directory.Trim() + ";Extensions=asc,csv,tab,txt;Persist Security Info=False"; string connectionString = "Driver={Microsoft Text Driver (*.txt;*.csv)};DefaultDir=" + directory.Trim() + "Extended properties=\"ColNameHeader=True;Format=CSVDelimited;\""; odbcconn = new System.Data.Odbc.OdbcConnection(connectionString.Trim()); odbcconn.Open(); //Fetch records from CSV string odbcsql = "select * from [" + filename + "]"; odbcda = new System.Data.Odbc.OdbcDataAdapter(odbcsql, odbcconn); //Fill dataset with the records from CSV file odbcda.Fill(taxds, "Taxes"); } catch (Exception e) { Console.WriteLine(e.Message); } finally { odbcconn.Close(); DestroyIniFile(path); } return(taxds); }
public DataSet GetDataSet(string sql, ref System.Data.Odbc.OdbcDataAdapter sda) { try { DataSet ds = new DataSet(); this.Open(); IDbCommand com = DBF.getDBCommand(); com.CommandText = sql; com.Connection = DBF.getDBConnection(); sda = (System.Data.Odbc.OdbcDataAdapter)DBF.getDataAdapter(com); sda.Fill(ds); this.Close(); return(ds); } catch (Exception ex) { MessageBox.Show("Error:" + sql + ex.Message); return(null); } }
public static DataTable LoadCsv(string importFolder, string strFileName) { //in some function System.Data.Odbc.OdbcConnection conn; DataTable dt = new DataTable(); System.Data.Odbc.OdbcDataAdapter da; string connectionString; connectionString = @"Driver={Microsoft Text Driver (*.txt; *.csv)};Dbq=" + importFolder + ";"; conn = new System.Data.Odbc.OdbcConnection(connectionString); //we only pass it the folder. The csv file import is in the query which follows da = new System.Data.Odbc.OdbcDataAdapter("select * from [" + strFileName + "]", conn); da.Fill(dt); return(dt); }
public int ListarDados(cDados obj, ref cDados[] array) { string sql; try { sql = "SELECT ID, id_avaliacao, data_hora, freq_cardiaca FROM dados WHERE id_avaliacao = " + obj.id_avaliacao.ToString(); sqlConn = new System.Data.Odbc.OdbcConnection(connString); sqlConn.Open(); sqlCmd = new System.Data.Odbc.OdbcCommand(sql, sqlConn); sqlAdapter = new System.Data.Odbc.OdbcDataAdapter(); sqlAdapter.SelectCommand = sqlCmd; sqlDataSet = new System.Data.DataSet(); sqlAdapter.Fill(sqlDataSet); System.Data.DataTable dt = sqlDataSet.Tables[0]; foreach (System.Data.DataRow row in dt.Rows) { Array.Resize(ref array, array.Length + 1); System.Data.DataRow linha = row; array[array.Length - 1] = new cDados(); array[array.Length - 1].id = int.Parse(linha["id"].ToString()); array[array.Length - 1].fc = int.Parse(linha["freq_cardiaca"].ToString()); array[array.Length - 1].data = DateTime.Parse(linha["data_hora"].ToString()); } sqlConn.Close(); return(dt.Rows.Count); } catch (Exception Ex) { return(-1); } }
public int UpdateDataTable(string sql, System.Data.DataTable dt, System.Data.Odbc.OdbcDataAdapter sda) { int i = 0; try { System.Data.Odbc.OdbcCommandBuilder builder = new System.Data.Odbc.OdbcCommandBuilder(sda); sda.UpdateCommand = builder.GetUpdateCommand(); if (dt.GetChanges() != null) { i = sda.Update(dt); dt = GetDataTable(sql); } } catch (Exception ex) { MessageBox.Show("Error:" + ex.Message.ToString()); return(-1); } return(i); }
public static System.Data.DataSet ExecuteDatasetQueryOnDB(string sSQL, string sConnectionString) { System.Data.Odbc.OdbcDataAdapter QDataAdapter = null; DataSet QDataSet = null; try { QDataSet = new DataSet(); QDataAdapter = new System.Data.Odbc.OdbcDataAdapter(sSQL, sConnectionString); QDataAdapter.Fill(QDataSet); return QDataSet; } finally { if (QDataSet != null) QDataSet.Dispose(); QDataSet = null; if (QDataAdapter != null) QDataAdapter.Dispose(); QDataAdapter = null; } }
/// <summary> /// /// </summary> /// <returns></returns> public string[] GetDbTables(DbConnect dbConnect) { System.Data.Odbc.OdbcCommand showTableCommand = dbConnect.CreateCommand(); showTableCommand.CommandText = @"SELECT RDB$RELATION_NAME FROM RDB$RELATIONS WHERE RDB$SYSTEM_FLAG = 0;"; DataTable tableNamesTable = new DataTable("Table Names"); System.Data.Odbc.OdbcDataAdapter adapter = new System.Data.Odbc.OdbcDataAdapter(); adapter.SelectCommand = showTableCommand; adapter.Fill(tableNamesTable); List <string> dbTableList = new List <string>(); foreach (DataRow dRow in tableNamesTable.Rows) { string tableString = dRow[0].ToString(); dbTableList.Add(tableString.Trim()); } return(dbTableList.ToArray()); }
public static DataTable ReadCSV(string file) { string path = System.IO.Path.GetDirectoryName(file).ToString(); string filename = System.IO.Path.GetFileName(file).ToString(); string strConn = @"Driver={Microsoft Text Driver (*.txt; *.csv)};Dbq=" + path + @"\;Extensions=asc,csv,tab,txt"; try { System.Data.Odbc.OdbcConnection conn = new System.Data.Odbc.OdbcConnection(strConn); System.Data.Odbc.OdbcDataAdapter da = new System.Data.Odbc.OdbcDataAdapter("Select * from [" + filename + "]", conn); DataTable dt = new DataTable(); da.Fill(dt); Console.WriteLine(dt.Rows.Count.ToString()); return(dt); } catch (Exception ex) { CommonDoubleM.LogDM("Import CSV failed: " + ex.Message); return(null); } }
public static DbDataAdapter CreateDataAdapter(DbCommand dbCommand, DbConnection connection) { DbDataAdapter adapter; //we can't construct an adapter directly //So let's run around the block 3 times, before potentially crashing if (connection is System.Data.SqlClient.SqlConnection) adapter = new System.Data.SqlClient.SqlDataAdapter(dbCommand.CommandText, connection as SqlConnection); else if (connection is System.Data.OleDb.OleDbConnection) adapter = new System.Data.OleDb.OleDbDataAdapter(dbCommand.CommandText, connection as System.Data.OleDb.OleDbConnection); else if (connection is System.Data.Odbc.OdbcConnection) adapter = new System.Data.Odbc.OdbcDataAdapter(dbCommand.CommandText, connection as System.Data.Odbc.OdbcConnection); else if (connection is System.Data.SqlServerCe.SqlCeConnection) adapter = new System.Data.SqlServerCe.SqlCeDataAdapter(dbCommand.CommandText, connection as System.Data.SqlServerCe.SqlCeConnection); //TODO: Add more DbConnection kinds as they become invented else { throw new Exception("[CreateDataAdapter] Unknown DbConnection type: " + connection.GetType().FullName); } return adapter; }
public bool MaterializaPessoa(cPessoa objPessoa) { string sql; try { sql = "SELECT ID, nome, sexo, dt_nascimento FROM pessoa where ID = " + objPessoa.ID.ToString(); sqlConn = new System.Data.Odbc.OdbcConnection(connString); sqlConn.Open(); sqlCmd = new System.Data.Odbc.OdbcCommand(sql, sqlConn); sqlAdapter = new System.Data.Odbc.OdbcDataAdapter(); sqlAdapter.SelectCommand = sqlCmd; sqlDataSet = new System.Data.DataSet(); sqlAdapter.Fill(sqlDataSet, "pessoa"); System.Data.DataTable dt = sqlDataSet.Tables["pessoa"]; if (dt.Rows.Count > 0) { System.Data.DataRow linha = dt.Rows[0]; objPessoa.ID = int.Parse(linha["ID"].ToString()); objPessoa.sNome = linha["nome"].ToString(); objPessoa.sSexo = linha["sexo"].ToString(); objPessoa.dtDataNasc = DateTime.Parse(linha["dt_nascimento"].ToString()); } sqlConn.Close(); return(true); } catch (Exception Ex) { return(false); } }
private void button5_Click(object sender, EventArgs e) { try { dataSet11.Table.Rows.Clear(); dataSet11.Table.Columns.Clear(); odbcConnection1.ConnectionString = "Dsn=Excel Files;dbq=" + FexName + ";defaultdir=D:;driverid=1046;maxbuffersize=2048;pagetimeout=5"; odbcConnection1.Open(); odbcDataAdapter1 = new System.Data.Odbc.OdbcDataAdapter("SELECT* FROM" + " " + "[" + comboBox1.Text.ToString() + "$]", odbcConnection1.ConnectionString); odbcDataAdapter1.Update(dataSet11.Table); odbcDataAdapter1.Fill(dataSet11.Table); dataGridView1.DataSource = dataSet11.Table; odbcConnection1.Close(); } catch (System.Data.Odbc.OdbcException) { MessageBox.Show("Выберите файл!", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error); } catch (System.InvalidOperationException) { MessageBox.Show("Выберите файл!", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error); } }
private void pickBulkCSVFile_Click(object sender, EventArgs e) { DialogResult result = htmlEmailPicker.ShowDialog(); if (result == DialogResult.OK) { string filename = htmlEmailPicker.FileName; // Graciously taken from https://social.msdn.microsoft.com/Forums/vstudio/en-US/859ff0ed-40f9-41df-bf81-b8413465d053/csv-import-using-c?forum=csharpgeneral System.Data.Odbc.OdbcConnection conn; DataTable dt = new DataTable(); System.Data.Odbc.OdbcDataAdapter da; string file = System.IO.Path.GetFileName(filename); string folder = System.IO.Path.GetDirectoryName(filename); // Gotta construct a schema.ini file that specifies everything come in as text // http://stackoverflow.com/questions/1688497/load-csv-into-oledb-and-force-all-inferred-datatypes-to-string // Open connection once to get the schema info conn = new System.Data.Odbc.OdbcConnection(@"Driver={Microsoft Text Driver (*.txt; *.csv)};Dbq=" + folder + ";Extensions=asc,csv,tab,txt;Persist Security Info=False;"); da = new System.Data.Odbc.OdbcDataAdapter("select * from [" + file + "]", conn); da.Fill(dt); StringBuilder schema = new StringBuilder(); schema.AppendLine("[" + file + "]"); schema.AppendLine("ColNameHeader=True"); // Validate that the minimum headers exist Dictionary <string, bool> required_fields = new Dictionary <string, bool> { { "To:", false }, { "CC:", false }, { "BCC:", false }, { "Site", false }, { "View Location", false } }; for (int i = 0; i < dt.Columns.Count; i++) { if (required_fields.ContainsKey(dt.Columns[i].ColumnName)) { required_fields[dt.Columns[i].ColumnName] = true; } } // Break if headers not correct if (required_fields.ContainsValue(false)) { MessageBox.Show("CSV headers are not correct. The correct format is:\nTo:,CC:,BCC:,Site,View Location,Filter Field Name 1,Filter Values 1,..."); return; } for (int i = 0; i < dt.Columns.Count; i++) { schema.AppendLine("col" + (i + 1).ToString() + "=\"" + dt.Columns[i].ColumnName + "\" Text"); } string schemaFileName = folder + @"\Schema.ini"; TextWriter tw = new StreamWriter(schemaFileName); tw.WriteLine(schema.ToString()); tw.Close(); // Open again, schema.ini should be in use DataTable dt2 = new DataTable(); conn = new System.Data.Odbc.OdbcConnection(@"Driver={Microsoft Text Driver (*.txt; *.csv)};Dbq=" + folder + ";Extensions=asc,csv,tab,txt;Persist Security Info=False;"); da = new System.Data.Odbc.OdbcDataAdapter("select * from [" + file + "]", conn); da.Fill(dt2); bulkEmailPreview.DataSource = dt2; // Clean out the schema file File.Delete(schemaFileName); } }
private void check_daily_dbf_date(String table_name, String code) { foreach (String path in folders) { if (path.Contains("old")) continue; System.Data.Odbc.OdbcConnection conn = new System.Data.Odbc.OdbcConnection(); try { String p = path.Replace(" ", ""); String table = p + "\\" + table_name + ".DBF"; string connStr = @"Driver={Microsoft Visual FoxPro Driver};SourceType=DBF;SourceDB=" + table + ";Exclusive=No;NULL=NO;Collate=Machine;BACKGROUNDFETCH=NO;DELETED=NO"; conn.ConnectionString = connStr; if (!File.Exists(table)) { MessageBox.Show(table + " is not exist"); continue; } conn.Open(); String sql = @"select * from " + table; System.Data.Odbc.OdbcDataAdapter dbf_da = new System.Data.Odbc.OdbcDataAdapter(sql, conn); DataTable dbf_dt = new DataTable(); dbf_dt.Clear(); dbf_da.Fill(dbf_dt); conn.Close(); foreach (DataRow row in dbf_dt.Rows) { DateTime in_date = Convert.ToDateTime(row[11]); DateTime bill_date = Convert.ToDateTime(row[13]); if (in_date.ToString("yyyy-MM-dd") != dateText.Text || bill_date.ToString("yyyy-MM-dd") != dateText.Text) logList.Items.Add(table + ": REF_NUM: " + row[0] + " IN_DATE: " + in_date.ToString("yyyy-MM-dd") + " BILL_DATE: " + bill_date.ToString("yyyy-MM-dd")); } } catch (Exception ex) { } } }
private void start_daily_import_252(String table_name, String code) { SqlConnection sql_conn; SqlCommand sql_cmd; SqlDataAdapter da; DataTable dt = new DataTable(); /*Connect to Sql server*/ string strConnection = "user id=sa;password=wang419420;"; strConnection += "initial catalog=fsrDataOrig;Server=192.168.3.252;"; strConnection += "Connect Timeout=30"; sql_conn = new SqlConnection(strConnection); sql_cmd = new SqlCommand("select * from dbo." + table_name); sql_cmd.Connection = sql_conn; da = new System.Data.SqlClient.SqlDataAdapter(sql_cmd); //da.Fill(dt); da.FillSchema(dt, System.Data.SchemaType.Mapped); /*Read DBF file content*/ foreach (String path in folders) { if (path.Contains("old")) continue; System.Data.Odbc.OdbcConnection conn = new System.Data.Odbc.OdbcConnection(); try { String p = path.Replace(" ", ""); String table = p + "\\" + table_name + ".DBF"; string connStr = @"Driver={Microsoft Visual FoxPro Driver};SourceType=DBF;SourceDB=" + table + ";Exclusive=No;NULL=NO;Collate=Machine;BACKGROUNDFETCH=NO;DELETED=NO"; conn.ConnectionString = connStr; if (!File.Exists(table)) { MessageBox.Show(table + " is not exist"); continue; } conn.Open(); String sql; if (table.Contains("A_TRAN")) sql = @"select ref_num, outlet, tran_type, in_date from " + table; else sql = @"select * from " + table; System.Data.Odbc.OdbcDataAdapter dbf_da = new System.Data.Odbc.OdbcDataAdapter(sql, conn); DataTable dbf_dt = new DataTable(); dbf_dt.Clear(); dbf_da.Fill(dbf_dt); conn.Close(); int year = path.IndexOf('2'); DateTime date = Convert.ToDateTime(path.Substring(year, 10).Replace('\\', '-')); int k = 0; //System.Console.WriteLine(table); for (int j = 0; j < dbf_dt.Rows.Count; j++) { if (table.Contains("A_PAY")) { DataRow newrow = dt.NewRow(); for (k = 0; k < dbf_dt.Columns.Count; k++) { newrow[k] = dbf_dt.Rows[j][k]; } newrow[k] = date; dt.Rows.Add(newrow); } else if (table.Contains("A_TRAN")) { DataRow newrow = dt.NewRow(); newrow[0] = dbf_dt.Rows[j][0]; newrow[3] = dbf_dt.Rows[j][1]; newrow[5] = dbf_dt.Rows[j][2]; newrow[11] = dbf_dt.Rows[j][3]; dt.Rows.Add(newrow); } else { DataRow newrow = dt.NewRow(); newrow[0] = code; for (k = 0; k < dbf_dt.Columns.Count; k++) { newrow[k + 1] = dbf_dt.Rows[j][k]; } if (table.Contains("T_ATT") || table.Contains("T_PAY")) newrow[k + 1] = date; dt.Rows.Add(newrow); } } sql_cmd.Connection.Open(); SqlCommandBuilder cb = new SqlCommandBuilder(da); da.Update(dt); sql_cmd.Connection.Close(); dt.Clear(); logList.Items.Insert(0, table); } catch (Exception ex) { MessageBox.Show(ex.ToString()); logList.Items.Insert(0, ex.ToString()); conn.Close(); sql_cmd.Connection.Close(); dt.Clear(); } } }
private void start_base_import(String table, String table_name, String code) { SqlConnection sql_conn; SqlCommand sql_cmd; SqlDataAdapter da; DataTable dt = new DataTable(); /*Connect to Sql server*/ string strConnection = "user id=sa;password=wang419420;"; strConnection += "initial catalog=" + dbname + ";Server=192.168.3.101\\foodsd;"; strConnection += "Connect Timeout=30"; sql_conn = new SqlConnection(strConnection); sql_cmd = new SqlCommand("select * from [banzhaoyun].[dbo].[" + table_name + "]"); sql_cmd.Connection = sql_conn; da = new System.Data.SqlClient.SqlDataAdapter(sql_cmd); da.Fill(dt); da.FillSchema(dt, System.Data.SchemaType.Mapped); /*Read DBF file content*/ try { //MessageBox.Show(table + " " + table_name + " " + code); System.Data.Odbc.OdbcConnection conn = new System.Data.Odbc.OdbcConnection(); //String table = "E:\\banzhaoyun\\base\\" + table_name + ".DBF"; string connStr = @"Driver={Microsoft Visual FoxPro Driver};SourceType=DBF;SourceDB=" + table + ";Exclusive=No;NULL=NO;Collate=Machine;BACKGROUNDFETCH=NO;DELETED=NO"; conn.ConnectionString = connStr; conn.Open(); String sql = @"select * from " + table; System.Data.Odbc.OdbcDataAdapter dbf_da = new System.Data.Odbc.OdbcDataAdapter(sql, conn); DataTable dbf_dt = new DataTable(); dbf_dt.Clear(); dbf_da.Fill(dbf_dt); conn.Close(); for (int j = 0; j < dbf_dt.Rows.Count; j++) { DataRow newrow = dt.NewRow(); newrow[0] = code; for (int k = 0; k < dbf_dt.Columns.Count; k++) newrow[k + 1] = dbf_dt.Rows[j][k]; dt.Rows.Add(newrow); } System.Console.WriteLine(table); sql_cmd.Connection.Open(); SqlCommandBuilder cb = new SqlCommandBuilder(da); da.Update(dt); sql_cmd.Connection.Close(); } catch (Exception ex) { MessageBox.Show(table + " " + table_name); } }
public OdbcCommandBuilder(System.Data.Odbc.OdbcDataAdapter adapter) { }
public static IDbDataAdapter CreateDataAdapter(EnumProviders provider) { IDbDataAdapter da; switch (provider) { case EnumProviders.SqlServer: da = new System.Data.SqlClient.SqlDataAdapter(); break; case EnumProviders.OleDb: da = new System.Data.OleDb.OleDbDataAdapter(); break; case EnumProviders.Odbc: da = new System.Data.Odbc.OdbcDataAdapter(); break; case EnumProviders.Oracle: throw new NotImplementedException("Provider not implemented"); break; default: da = new System.Data.SqlClient.SqlDataAdapter(); break; } return da; }
// UPLOAD BUTTON HANDLER ------------------------------------------------------------------------------------------------------- protected void uploadbutton_Click(object sender, EventArgs e) { // Get button ID Button getbuttonID = (Button)sender; string id = getbuttonID.ID.Replace("_button",""); // Use button ID to find similarly named upload control ID FileUpload uploadcontrol = (FileUpload)Form.FindControl(id); // Only upload if control has file selected if (uploadcontrol.HasFile) { // Add upload path String savePath = @"c:\temp\"; // Retrieve filename from upload control String fileName = uploadcontrol.FileName; // Save data to web server uploadcontrol.SaveAs(savePath + fileName); // Fill GridView // Establish text driver connection System.Data.Odbc.OdbcConnection csv_connection; System.Data.Odbc.OdbcDataAdapter csv_adapter; // Create temporary data table to store CSV data DataTable csv_data = new DataTable(); // Create connection string and execute connection to CSV string csv_connectionString = @"Driver={Microsoft Text Driver (*.txt; *.csv)};Dbq=" + savePath + ";"; csv_connection = new System.Data.Odbc.OdbcConnection(csv_connectionString); // Fill adapter with SELECT * query from CSV csv_adapter = new System.Data.Odbc.OdbcDataAdapter("select * from [" + fileName + "]", csv_connection); csv_adapter.Fill(csv_data); // Close CSV connection csv_connection.Close(); // Find GridView and fill GridView filedata = (GridView)Form.FindControl(id + "_table"); filedata.DataSource = csv_data; filedata.DataBind(); // SESSION MODIFICATION // DataSet session_datanew = new DataSet(); session_datanew.Tables.Add(csv_data); session_datanew.DataSetName = "PCADATA"; Registry.Registry registry = Registry.Registry.getRegistry(Session); registry.registerDataset(session_datanew); Analysis.ParameterStream stream = Analysis.ParameterStream.getStream(Session); stream.set("dataSetName", "PCADATA"); //----------------------// } }
/// <summary> /// Required method for Designer support - do not modify /// the contents of this method with the code editor. /// </summary> private void InitializeComponent() { this.numParticipants = new System.Windows.Forms.TextBox(); this.label1 = new System.Windows.Forms.Label(); this.label2 = new System.Windows.Forms.Label(); this.numberSims = new System.Windows.Forms.TextBox(); this.doSims = new System.Windows.Forms.Button(); this.torParmsCancel = new System.Windows.Forms.Button(); this.comboPrizeStructure = new System.Windows.Forms.ComboBox(); this.comboBlindStructure = new System.Windows.Forms.ComboBox(); this.label3 = new System.Windows.Forms.Label(); this.label5 = new System.Windows.Forms.Label(); this.odbcDataAdapterBlinds = new System.Data.Odbc.OdbcDataAdapter(); this.odbcInsertCommand1 = new System.Data.Odbc.OdbcCommand(); this.odbcConnectionBlinds = new System.Data.Odbc.OdbcConnection(); this.odbcSelectCommand1 = new System.Data.Odbc.OdbcCommand(); this.odbcDataAdapterPrizes = new System.Data.Odbc.OdbcDataAdapter(); this.odbcInsertCommand2 = new System.Data.Odbc.OdbcCommand(); this.odbcSelectCommand2 = new System.Data.Odbc.OdbcCommand(); this.odbcConnectionPrizes = new System.Data.Odbc.OdbcConnection(); this.label6 = new System.Windows.Forms.Label(); this.averageStack = new System.Windows.Forms.TextBox(); this.progressBar = new System.Windows.Forms.ProgressBar(); this.SuspendLayout(); // // numParticipants // this.numParticipants.Location = new System.Drawing.Point(352, 16); this.numParticipants.Name = "numParticipants"; this.numParticipants.TabIndex = 1; this.numParticipants.Text = "20"; // // label1 // this.label1.Location = new System.Drawing.Point(224, 16); this.label1.Name = "label1"; this.label1.TabIndex = 2; this.label1.Text = "Number of Players"; // // label2 // this.label2.Location = new System.Drawing.Point(224, 56); this.label2.Name = "label2"; this.label2.TabIndex = 2; this.label2.Text = "Number of Sims"; // // numberSims // this.numberSims.Location = new System.Drawing.Point(352, 56); this.numberSims.Name = "numberSims"; this.numberSims.TabIndex = 1; this.numberSims.Text = "20000"; // // doSims // this.doSims.Location = new System.Drawing.Point(48, 136); this.doSims.Name = "doSims"; this.doSims.Size = new System.Drawing.Size(104, 23); this.doSims.TabIndex = 5; this.doSims.Text = "Do Simulation"; this.doSims.Click += new System.EventHandler(this.doSims_Click); // // torParmsCancel // this.torParmsCancel.Location = new System.Drawing.Point(200, 136); this.torParmsCancel.Name = "torParmsCancel"; this.torParmsCancel.TabIndex = 6; this.torParmsCancel.Text = "Cancel"; this.torParmsCancel.Click += new System.EventHandler(this.torParmsCancel_Click); // // comboPrizeStructure // this.comboPrizeStructure.Location = new System.Drawing.Point(16, 40); this.comboPrizeStructure.Name = "comboPrizeStructure"; this.comboPrizeStructure.Size = new System.Drawing.Size(168, 21); this.comboPrizeStructure.TabIndex = 7; this.comboPrizeStructure.Text = "comboBox1"; // // comboBlindStructure // this.comboBlindStructure.Location = new System.Drawing.Point(16, 96); this.comboBlindStructure.Name = "comboBlindStructure"; this.comboBlindStructure.Size = new System.Drawing.Size(168, 21); this.comboBlindStructure.TabIndex = 8; this.comboBlindStructure.Text = "comboBox2"; // // label3 // this.label3.Location = new System.Drawing.Point(16, 16); this.label3.Name = "label3"; this.label3.TabIndex = 9; this.label3.Text = "Prize structure"; // // label5 // this.label5.Location = new System.Drawing.Point(16, 72); this.label5.Name = "label5"; this.label5.TabIndex = 10; this.label5.Text = "Blind Structure"; // // odbcDataAdapterBlinds // this.odbcDataAdapterBlinds.InsertCommand = this.odbcInsertCommand1; this.odbcDataAdapterBlinds.SelectCommand = this.odbcSelectCommand1; this.odbcDataAdapterBlinds.TableMappings.AddRange(new System.Data.Common.DataTableMapping[] { new System.Data.Common.DataTableMapping("Table", "BlindStructure", new System.Data.Common.DataColumnMapping[] { new System.Data.Common.DataColumnMapping("BlindStructureID", "BlindStructureID"), new System.Data.Common.DataColumnMapping("Name", "Name") }) }); // // odbcInsertCommand1 // this.odbcInsertCommand1.CommandText = "INSERT INTO BlindStructure(Name) VALUES (?)"; this.odbcInsertCommand1.Connection = this.odbcConnectionBlinds; this.odbcInsertCommand1.Parameters.Add(new System.Data.Odbc.OdbcParameter("Name", System.Data.Odbc.OdbcType.NVarChar, 50, "Name")); // // odbcConnectionBlinds // this.odbcConnectionBlinds.ConnectionString = "MaxBufferSize=2048;FIL=MS Access;DSN=TornamentSimData;PageTimeout=5;DBQ=B:\\PokerT" + "ornamentSim\\PokerTornamentSim\\TornamentSimData.mdb;DriverId=25"; // // odbcSelectCommand1 // this.odbcSelectCommand1.CommandText = "SELECT BlindStructureID, Name FROM BlindStructure"; this.odbcSelectCommand1.Connection = this.odbcConnectionBlinds; // // odbcDataAdapterPrizes // this.odbcDataAdapterPrizes.InsertCommand = this.odbcInsertCommand2; this.odbcDataAdapterPrizes.SelectCommand = this.odbcSelectCommand2; this.odbcDataAdapterPrizes.TableMappings.AddRange(new System.Data.Common.DataTableMapping[] { new System.Data.Common.DataTableMapping("Table", "PrizeStructures", new System.Data.Common.DataColumnMapping[] { new System.Data.Common.DataColumnMapping("PrizeStructureId", "PrizeStructureId"), new System.Data.Common.DataColumnMapping("Name", "Name") }) }); // // odbcInsertCommand2 // this.odbcInsertCommand2.CommandText = "INSERT INTO PrizeStructures(Name) VALUES (?)"; this.odbcInsertCommand2.Connection = this.odbcConnectionBlinds; this.odbcInsertCommand2.Parameters.Add(new System.Data.Odbc.OdbcParameter("Name", System.Data.Odbc.OdbcType.NVarChar, 50, "Name")); // // odbcSelectCommand2 // this.odbcSelectCommand2.CommandText = "SELECT PrizeStructureId, Name FROM PrizeStructures"; this.odbcSelectCommand2.Connection = this.odbcConnectionBlinds; // // odbcConnectionPrizes // this.odbcConnectionPrizes.ConnectionString = "MaxBufferSize=2048;FIL=MS Access;DSN=TornamentSimData;PageTimeout=5;DBQ=B:\\PokerT" + "ornamentSim\\PokerTornamentSim\\TornamentSimData.mdb;DriverId=25"; // // label6 // this.label6.Location = new System.Drawing.Point(224, 88); this.label6.Name = "label6"; this.label6.TabIndex = 11; this.label6.Text = "Average Stack"; // // averageStack // this.averageStack.Location = new System.Drawing.Point(352, 88); this.averageStack.Name = "averageStack"; this.averageStack.TabIndex = 12; this.averageStack.Text = "100"; // // progressBar // this.progressBar.Location = new System.Drawing.Point(16, 168); this.progressBar.Name = "progressBar"; this.progressBar.Size = new System.Drawing.Size(424, 23); this.progressBar.TabIndex = 13; // // TornamentParamaters // this.AutoScaleBaseSize = new System.Drawing.Size(5, 13); this.ClientSize = new System.Drawing.Size(464, 205); this.Controls.Add(this.progressBar); this.Controls.Add(this.averageStack); this.Controls.Add(this.label6); this.Controls.Add(this.label5); this.Controls.Add(this.label3); this.Controls.Add(this.comboBlindStructure); this.Controls.Add(this.comboPrizeStructure); this.Controls.Add(this.torParmsCancel); this.Controls.Add(this.doSims); this.Controls.Add(this.label1); this.Controls.Add(this.numParticipants); this.Controls.Add(this.label2); this.Controls.Add(this.numberSims); this.Name = "TornamentParamaters"; this.Text = "Tornament Paramaters"; this.Load += new System.EventHandler(this.TornamentParamaters_Load); this.ResumeLayout(false); }
private void btLoad_Click(object sender, System.EventArgs e) { try { System.Data.DataSet dataset = new System.Data.DataSet(); using (System.Data.Odbc.OdbcDataAdapter adapter = new System.Data.Odbc.OdbcDataAdapter(txtSqlQuery.Text, txtConnectionString.Text)) { adapter.Fill(dataset); } //Debug Trace dataset.Tables[0].RowDeleted += new System.Data.DataRowChangeEventHandler(frmSample9_RowDeleted); dataset.Tables[0].RowChanged += new System.Data.DataRowChangeEventHandler(frmSample9_RowChanged); dataset.Tables[0].ColumnChanged += new System.Data.DataColumnChangeEventHandler(frmSample9_ColumnChanged); lbRowsNumber.Text = "Rows: " + dataset.Tables[0].Rows.Count; dataGrid.FixedColumns = 1; dataGrid.FixedRows = 1; dataGrid.Columns.Clear(); DevAge.ComponentModel.BoundDataView bd = new DevAge.ComponentModel.BoundDataView(dataset.Tables[0].DefaultView); bd.AllowNew = chkAllowNew.Checked; bd.AllowEdit = chkEdit.Checked; bd.AllowDelete = chkAllowDelete.Checked; dataGrid.DataSource = bd; dataGrid.Columns[0].AutoSizeMode = SourceGrid.AutoSizeMode.MinimumSize; dataGrid.Columns[0].Width = 20; dataGrid.Columns.AutoSizeView(); } catch(Exception err) { DevAge.Windows.Forms.ErrorDialog.Show(this, err, "Error loading dataset"); } }
void BadQueries(string name, string password) { var command1 = new System.Data.Odbc.OdbcCommand("SELECT AccountNumber FROM Users " + // Noncompliant {{Make sure to sanitize the parameters of this SQL command.}} // ^^^^^^^^^^^^^^^^^^^^^^^^^^^^ "WHERE Username='******' AND Password='******'"); command1.CommandText = "SELECT AccountNumber FROM Users " + // Noncompliant // ^^^^^^^^^^^^^^^^^^^^ "WHERE Username='******' AND Password='******'"; var command2 = new System.Data.Odbc.OdbcDataAdapter("SELECT AccountNumber FROM Users " + // Noncompliant "WHERE Username='******' AND Password='******'", ""); var command3 = new System.Data.OleDb.OleDbCommand("SELECT AccountNumber FROM Users " + // Noncompliant "WHERE Username='******' AND Password='******'"); command3.CommandText = "SELECT AccountNumber FROM Users " + // Noncompliant "WHERE Username='******' AND Password='******'"; var command4 = new System.Data.OleDb.OleDbDataAdapter("SELECT AccountNumber FROM Users " + // Noncompliant "WHERE Username='******' AND Password='******'", ""); var command5 = new Oracle.ManagedDataAccess.Client.OracleCommand("SELECT AccountNumber FROM Users " + // Noncompliant "WHERE Username='******' AND Password='******'"); command5.CommandText = "SELECT AccountNumber FROM Users " + // Noncompliant "WHERE Username='******' AND Password='******'"; var command6 = new Oracle.ManagedDataAccess.Client.OracleDataAdapter("SELECT AccountNumber FROM Users " + // Noncompliant "WHERE Username='******' AND Password='******'", ""); var command7 = new System.Data.SqlServerCe.SqlCeCommand("SELECT AccountNumber FROM Users " + // Noncompliant "WHERE Username='******' AND Password='******'"); command7.CommandText = "SELECT AccountNumber FROM Users " + // Noncompliant "WHERE Username='******' AND Password='******'"; var command8 = new System.Data.SqlServerCe.SqlCeDataAdapter("SELECT AccountNumber FROM Users " + // Noncompliant "WHERE Username='******' AND Password='******'", ""); var command9 = new System.Data.SqlClient.SqlCommand("SELECT AccountNumber FROM Users " + // Noncompliant "WHERE Username='******' AND Password='******'"); command9.CommandText = "SELECT AccountNumber FROM Users " + // Noncompliant "WHERE Username='******' AND Password='******'"; var command10 = new System.Data.SqlClient.SqlDataAdapter("SELECT AccountNumber FROM Users " + // Noncompliant "WHERE Username='******' AND Password='******'", ""); }