private void insert_appointment_Load(object sender, EventArgs e) { string constr = "Data source = orcl; User Id = hr; Password =hr; "; string cmdstr = "select * from APPOINTMENT"; OracleConnection conn = new OracleConnection(constr); conn.Open(); OracleCommand cmd = new OracleCommand(); cmd.Connection = conn; cmd.CommandText = cmdstr; cmd.CommandType = CommandType.Text; OracleDataReader dr = cmd.ExecuteReader(); while (dr.Read()) { if ((dr[2].ToString()) == user.Username) { dataGridView1.Rows.Add(dr[0], dr[1], dr[3], dr[4], true); } else { dataGridView1.Rows.Add(dr[0], dr[1], dr[3], dr[4], false); } } dr.Close(); conn.Clone(); }
public static void InsertarFoto(Session _userSession) { try { using (var conexion = new OracleConnection(ConexionString)) { conexion.Open(); var comando = "insert into cooper_adm.recepcion_uva_foto " + "(OBSERVACION,IMAGEN,LECTURA,FECHA,COSECHA,ID_PLANTA,NUM_TICKET_ATENCION,TIPO_CONTROL) " + "VALUES(:observacion,:imagen,0,sysdate,:cosecha,:planta,:ticket,:control)"; using (var cmd = new OracleCommand(comando, conexion)) { OracleParameter[] parametros = new OracleParameter[] { //new OracleParameter("id_recepcion",_userSession.Ticket), new OracleParameter("observacion", "Ningún problema."), new OracleParameter("imagen", _userSession.Imagen), new OracleParameter("cosecha", DateTime.Now.Year), //new OracleParameter("fecha",DateTime.Now.ToString("dd-MM-yyyy")), new OracleParameter("planta", _userSession.ID_Planta), new OracleParameter("ticket", _userSession.Ticket), new OracleParameter("control", _userSession.Tipo_Control) }; cmd.Parameters.AddRange(parametros); cmd.ExecuteNonQuery(); } conexion.Clone(); EscribirEnLog("Imagen Insertada correctamente en BD."); } } catch (Exception) { EscribirEnLog("Error al insertar Imagen en Base de Datos."); } }
/* * public bool AgregarPlazo(Modelo.Plazos plazo) * { * * try * { * Conexion conexion = new Conexion(); * OracleConnection conn = new OracleConnection(); * conn = conexion.getConn(); * * conn.Open(); * OracleCommand comando = new OracleCommand("AGREGARPLAZO", conn); * * comando.CommandType = System.Data.CommandType.StoredProcedure; * * comando.Parameters.Add("ID_PLAZO", OracleDbType.Int32).Value = plazo.ID_Plazo1; * comando.Parameters.Add("FECHA_INICIO", OracleDbType.Date).Value = plazo.Fecha_Inicio1; * comando.Parameters.Add("FECHA_TERMINO", OracleDbType.Date).Value = plazo.Fecha_Termino1; * comando.Parameters.Add("ID_TAREA", OracleDbType.Int32).Value = plazo.ID_TAREA1; * comando.ExecuteNonQuery(); * conn.Close(); * * } * catch (Exception) * { * * return false; * } * * return true; * * } */ public bool AgregarPlazos(Modelo.Plazos plazo) { try { Conexion conexion = new Conexion(); OracleConnection conn = new OracleConnection(); conn = conexion.getConn(); conn.Open(); OracleCommand comando = new OracleCommand("AGREGARPLAZO", conn); comando.CommandType = System.Data.CommandType.StoredProcedure; comando.Parameters.Add("ID_PLAZO", OracleDbType.Int32).Value = plazo.ID_Plazo1; comando.Parameters.Add("FECHA_INICIO", OracleDbType.Date).Value = plazo.Fecha_Inicio1; comando.Parameters.Add("FECHA_TERMINO", OracleDbType.Date).Value = plazo.Fecha_Termino1; comando.Parameters.Add("ID_TAREA", OracleDbType.Int32).Value = plazo.ID_TAREA1; comando.ExecuteNonQuery(); conn.Clone(); } catch (Exception) { return(false); } return(true); }
static void Main(string[] args) { string connectionString = "Data Source=(DESCRIPTION=(ADDRESS_LIST=(ADDRESS=(PROTOCOL=TCP)(HOST=192.168.0.117)(PORT=1521)))(CONNECT_DATA=(SERVER=DEDICATED)(SERVICE_NAME=RMS)));User Id=varsis;Password=pwdv4r51s123"; OracleConnection con = new OracleConnection(connectionString); con.Open(); OracleCommand cmd = con.CreateCommand(); cmd.CommandText = "Select * from carone.AA2CPARA"; OracleDataReader reader = cmd.ExecuteReader(); string codigo = "Codigo"; string acesso = "Acesos"; string conteudo = "Conteudo"; Console.WriteLine($"{codigo}\t{acesso}\t{conteudo}\n"); while (reader.Read()) { try { codigo = reader.GetString(0); acesso = string.IsNullOrEmpty(reader.GetString(1)) ? "Vazio" : reader.GetString(1); conteudo = string.IsNullOrEmpty(reader.GetString(2)) ? "Vazio" : reader.GetString(2); Console.WriteLine($"{codigo}\t{acesso}\t{conteudo}\n"); } catch (Exception e) { } } con.Clone(); }
protected void Page_Load(object sender, EventArgs e) { if (!Page.IsPostBack) { try { IncarcareRaport(); LabelPrincipalErr.Text = ""; } catch (Exception ex) { LabelPrincipalErr.Text = "Nu se poate realiza conexiunea la baza de date: " + ex.Message; LabelPrincipalErr.ForeColor = Color.Red; } finally { con.Clone(); } } if (Session["Fluturasi"] != null) { CrystalReportViewer1.ReportSource = Session["Fluturasi"]; } }
/*關閉鏈接*/ public void CloseConn() { if (Connection.State != ConnectionState.Closed) { Connection.Clone(); } }
public int InsertData(string query) { _conn = _db.GetConnect(); _conn.Open(); try { OracleCommand cmd = new OracleCommand(query, _conn); int checkSuccs = cmd.ExecuteNonQuery(); _conn.Clone(); if (checkSuccs >= 1) { return(1); } else { return(0); } } catch (Exception ex) { System.Windows.Forms.MessageBox.Show("Error!" + ex); } return(0); }
public Boolean AgregarFlujoTareas(string NombreTarea) { Boolean confirmo; try { Conexion conexion = new Conexion(); OracleConnection conn = new OracleConnection(); conn = conexion.getConn(); conn.Open(); OracleCommand comando = new OracleCommand("AGREGARFLUJOTAREA", conn); comando.CommandType = System.Data.CommandType.StoredProcedure; comando.Parameters.Add("@NOMBRE", OracleDbType.Varchar2).Value = NombreTarea; comando.ExecuteNonQuery(); conn.Clone(); confirmo = true; } catch (Exception e) { confirmo = false; } return(confirmo); }
/// <summary> /// Execute o comando delete no banco de dados. /// </summary> /// <param name="query">Sql que será executado.</param> /// <returns>Retorna o número de linhas afetadas</returns> public string Delete(string query) { using (connection = new OracleConnection(_connectionString)) using (command = new OracleCommand(query, connection)) { try { connection.Open(); connection.BeginTransaction(); int numberRowsAffecteds = command.ExecuteNonQuery(); command.Transaction.Commit(); return(numberRowsAffecteds.ToString()); } catch (InvalidOperationException ex) { command.Transaction.Rollback(); return($"Error when deleting data. Message: {ex.Message}"); } catch (Exception ex) { command.Transaction.Rollback(); return($"Error when deleting data. Message: {ex.Message}"); } finally { connection.Clone(); } } }
static void Main(string[] args) { OracleConnection conn = new OracleConnection(); try { conn.ConnectionString = ConfigurationManager.ConnectionStrings["oradb"].ConnectionString; conn.Open(); string sql = " select id,content from test"; // C# OracleCommand cmd = new OracleCommand(sql, conn); cmd.CommandType = CommandType.Text; OracleDataReader dr = cmd.ExecuteReader(); // C# List <string> contents = new List <string>(); while (dr.Read()) { contents.Add(dr["content"].ToString()); } } catch (Exception ex) { MessageBox.Show(ex.Message); } finally { conn.Clone(); } }
public bool Close() { try { // Verifica se existe conexão aberta if (objConnection != null) { if (objConnection.State == ConnectionState.Open) { objConnection.Clone(); // Fecha conexão } } return(true); } catch (Exception ex) { throw ex; } finally { // Finaliza objetos objConnection = null; } }
public static void InsertarFotoRecepcion(Session _userSession) { try { using (var conexion = new OracleConnection(ConexionString)) { conexion.Open(); var comando = "insert into cooper_adm.recepcion_uva_foto " + "(ID_RECEPCION_UVA,OBSERVACION,IMAGEN,LECTURA,FECHA,COSECHA,ID_PLANTA,NUM_TICKET_ATENCION,TIPO_CONTROL) " + "VALUES(:id_recepcion,:observacion,:imagen,:lectura,sysdate,:cosecha,:planta,:ticket,:control)"; using (var cmd = new OracleCommand(comando, conexion)) { OracleParameter[] parametros = new OracleParameter[] { new OracleParameter("id_recepcion", _userSession.Id_Recepcion), new OracleParameter("observacion", "No hay problemas."), new OracleParameter("imagen", _userSession.Imagen), new OracleParameter("lectura", _userSession.Intento), new OracleParameter("cosecha", DateTime.Now.Year), new OracleParameter("planta", _userSession.Id_Planta), new OracleParameter("ticket", _userSession.NUM_TICKET), new OracleParameter("control", 2), }; cmd.Parameters.AddRange(parametros); cmd.ExecuteNonQuery(); } conexion.Clone(); EscribirEnLog("Imagen Insertada correctamente en BD."); } } catch (OracleException error) { EscribirEnLog("Error al Insertar Imagen. Error: " + error.Message); } }
public string ConnectCheck(Dictionary <string, string> NewConnData) { string NewSource = "Data Source=(DESCRIPTION =(ADDRESS = (PROTOCOL = " + NewConnData["protocol"] + ")(HOST = " + NewConnData["host"] + ")(PORT = " + NewConnData["port"] + ")) (CONNECT_DATA =(SERVER = " + NewConnData["server"] + ")(SERVICE_NAME = " + NewConnData["servicename"] + ") )); User Id=" + NewConnData["id"] + ";Password="******"pw"] + ";"; conn.ConnectionString = NewSource; try { conn.Open(); conn.Clone(); return(NewSource); } catch (Exception ex) { conn.Clone(); NewSource = ""; return(""); } }
public void dbClose() { try { conn.Clone(); Console.WriteLine("오라클 접속 해제"); } catch (OracleException e) { Console.WriteLine("오라클 해제오류: " + e.Message); } }
private static void CallProcedure(OracleConnection conn) { try { var sql = "Get_Employee_Info"; OracleCommand cmd = new OracleCommand(sql, conn); // Видом Command является StoredProcedure cmd.CommandType = CommandType.StoredProcedure; // Добавить параметр @p_Emp_Id и настроить его значение = 100. cmd.Parameters.Add("@p_Emp_Id", OracleDbType.Int32).Value = 100; // Добавить параметр @v_Emp_No вида Varchar(20). cmd.Parameters.Add(new OracleParameter("@v_Emp_No", OracleDbType.Varchar2, 20)); cmd.Parameters.Add(new OracleParameter("@v_First_Name", OracleDbType.Varchar2, 50)); cmd.Parameters.Add(new OracleParameter("@v_Last_Name", OracleDbType.Varchar2, 50)); cmd.Parameters.Add(new OracleParameter("@v_Hire_Date", OracleDbType.Date)); // Зарегистрировать параметр @v_Emp_No как OUTPUT. cmd.Parameters["@v_Emp_No"].Direction = ParameterDirection.Output; cmd.Parameters["@v_First_Name"].Direction = ParameterDirection.Output; cmd.Parameters["@v_Last_Name"].Direction = ParameterDirection.Output; cmd.Parameters["@v_Hire_Date"].Direction = ParameterDirection.Output; // Выполнить процедуру. cmd.ExecuteNonQuery(); // Получить выходные значения. string empNo = cmd.Parameters["@v_Emp_No"].Value.ToString(); string firstName = cmd.Parameters["@v_First_Name"].Value.ToString(); string lastName = cmd.Parameters["@v_Last_Name"].Value.ToString(); object hireDateObj = cmd.Parameters["@v_Hire_Date"].Value; Console.WriteLine("hireDateObj type: " + hireDateObj.GetType().ToString()); OracleDate hireDate = (OracleDate)hireDateObj; Console.WriteLine("Emp No: " + empNo); Console.WriteLine("First Name: " + firstName); Console.WriteLine("Last Name: " + lastName); Console.WriteLine("Hire Date: " + hireDate); } catch (Exception e) { Console.WriteLine(e); throw; } finally { conn.Clone(); conn.Dispose(); conn = null; } }
static void dbClose(OracleConnection conn) { try { conn.Clone(); Console.WriteLine("오라클 접속 해제 !!"); } catch (OracleException oe) { Console.WriteLine("오라클 해제 오류 : " + oe.Message); } }
private int ExecuteDelete(string sql) { OracleConnection connection = new OracleConnection(connectionString); OracleCommand command = new OracleCommand(sql); command.CommandType = CommandType.Text; command.Connection = connection; //Abre a conexão e executa o comando connection.ConnectionTimeout.Equals(15); connection.Open(); connection.Clone(); return(command.ExecuteNonQuery()); }
User IDataPump_Login.isAlive(string tb_User) { User temp_user = null; try { //conn.ConnectionString = ConfigurationManager.ConnectionStrings["oradb"].ConnectionString; conn.ConnectionString = @"Data Source=(DESCRIPTION=(ADDRESS_LIST=(ADDRESS=(PROTOCOL=TCP)(HOST=59.110.237.142)(PORT=1521)))(CONNECT_DATA=(sid =lwhy)));User Id=lwhy;Password=123"; conn.Open(); string sql = " select * from IUSER where unickname = " + "\'" + tb_User + "\'"; // C# OracleCommand cmd = new OracleCommand(sql, conn); OracleDataReader dr = cmd.ExecuteReader(); // C# if (dr.HasRows) { temp_user = new User(); while (dr.Read()) { temp_user.userid = (int)dr["userid"]; temp_user.nickname = dr["unickname"].ToString(); temp_user.password = dr["upassword"].ToString(); if (dr["ustatue"].ToString() == "o") { temp_user.isOnline = true; } else if (dr["ustatue"].ToString() == "f") { temp_user.isOnline = false; } else { throw new Exception(); } } } Console.Write(temp_user.nickname); } catch (Exception ex) { } finally { conn.Clone(); } return(temp_user); }
List <Question> IDataPumpSearchQueManager.SetOfSubQuestion(int Cla)//指示课程分类的那个String数组类 ques存储cla这个分类下所有题目 { OracleConnection conn = new OracleConnection(); List <Question> temp_lQuestion = new List <Question>(); try { //conn.ConnectionString = ConfigurationManager.ConnectionStrings["oradb"].ConnectionString; conn.ConnectionString = @"Data Source=(DESCRIPTION=(ADDRESS_LIST=(ADDRESS=(PROTOCOL=TCP)(HOST=59.110.237.142)(PORT=1521)))(CONNECT_DATA=(sid =lwhy)));User Id=lwhy;Password=123"; conn.Open(); string sql = " select * from QUESTION where qid in (select qid from CLASSFICATIONMAP where cid = " + Cla + ")"; // C# Console.Write(sql); OracleCommand cmd = new OracleCommand(sql, conn); OracleDataReader dr = cmd.ExecuteReader(); // C# if (dr.HasRows) { while (dr.Read()) { Question temp_question = new Question(); temp_question.questionId = (int)dr["qid"]; temp_question.title = dr["title"].ToString(); temp_question.body = dr["body"].ToString(); temp_question.answer = dr["answer"].ToString(); temp_question.tags = dr["tags"].ToString(); String str = dr["type"].ToString();//这句之后要进行思考。 temp_question.type = str[0]; temp_lQuestion.Add(temp_question); Console.Write(temp_question.title); } } else { throw new Exception("未能读取到相应的问题"); } } catch (Exception ex) { Console.Write(ex.Message); } finally { conn.Clone(); } return(temp_lQuestion); }
static void Main(string[] args) { //connection vers l'instance ORCL //string cs = "Data source = gdna10:User Id = ug283f20:Password=k5e7jc:"; string cs = "Data Source=(DESCRIPTION = (ADDRESS_LIST = (ADDRESS = (PROTOCOL = TCP)" + "(HOST = oracleadudb1.bdeb.qc.ca)(PORT = 1521))) (CONNECT_DATA = (SERVICE_NAME = gdna10) ));" + "User Id = UG214E30; Password=W5hx2u;"; OracleConnection connection = new OracleConnection(); connection.ConnectionString = cs; try { Console.WriteLine("connexion vers Oracle ..."); connection.Open(); //cree une requete string query = "SELECT LAST_NAME, FIRST_NAME FROM EMPLOYEES"; //REPARER L'EXCUTION DE LA REQUERE OracleCommand sql = new OracleCommand(); sql.Connection = connection; sql.CommandText = query; sql.CommandType = System.Data.CommandType.Text; //Recuperer le curseur OracleDataReader reader = sql.ExecuteReader(); //parcourir le curseur while (reader.Read()) { //afficher detail string nom, prenom; nom = (string)reader[0]; prenom = (string)reader[1]; Console.WriteLine("nom: {0} - prenom: {1}", nom, prenom); } } catch (Exception e) { Console.WriteLine(e.Message); } finally { connection.Clone(); } Console.ReadKey(); }
List <Question> IDataPumpSearchQueManager.QuestionClaSearch(String cla)//给出分类关键词,返回包含该关键词的所有问题,!!!!!!!!!!!!!!!!!!!!11 { OracleConnection conn = new OracleConnection(); List <Question> temp_lQuestion = new List <Question>(); try { //conn.ConnectionString = ConfigurationManager.ConnectionStrings["oradb"].ConnectionString; conn.ConnectionString = @"Data Source=(DESCRIPTION=(ADDRESS_LIST=(ADDRESS=(PROTOCOL=TCP)(HOST=59.110.237.142)(PORT=1521)))(CONNECT_DATA=(sid =lwhy)));User Id=lwhy;Password=123"; conn.Open(); string sql = "select * from QUESTION where qid in (select qid from CLASSFICATIONMAP natural join CLASSFICATION where TOPCLASSFICATION LIKE '%" + cla + "%' OR SECONDCLASSFICATION like '%" + cla + "%' OR THIRDCLASSFICATION like '%" + cla + "%' OR FORTHCLASSFICATION like '%" + cla + "%' OR FIFTHCLASSFICATION like '%" + cla + "%')"; // C# !!!!!!!!!!!!!!!!!!!!!!! OracleCommand cmd = new OracleCommand(sql, conn); OracleDataReader dr = cmd.ExecuteReader(); // C# if (dr.HasRows) { while (dr.Read()) { Question temp_question = new Question(); temp_question.questionId = (int)dr["qid"]; temp_question.title = dr["title"].ToString(); temp_question.body = dr["body"].ToString(); temp_question.answer = dr["answer"].ToString(); temp_question.tags = dr["tags"].ToString(); temp_question.type = dr["type"].ToString()[0];//这句之后要进行思考。 temp_lQuestion.Add(temp_question); } } else { throw new Exception("未能读取到相应的问题"); } } catch (Exception ex) { Console.Write(ex.Message); } finally { conn.Clone(); } return(temp_lQuestion); }
Information IDataPumpUserManage.getUserInfo(int userID) { OracleConnection conn = new OracleConnection(); Information ifo = new Information(); try { //conn.ConnectionString = ConfigurationManager.ConnectionStrings["oradb"].ConnectionString; conn.ConnectionString = @"Data Source=(DESCRIPTION=(ADDRESS_LIST=(ADDRESS=(PROTOCOL=TCP)(HOST=59.110.237.142)(PORT=1521)))(CONNECT_DATA=(sid =lwhy)));User Id=lwhy;Password=123"; conn.Open(); string sql = " select * from INFORMATION where iid=" + userID; // C# Console.Write(sql); OracleCommand cmd = new OracleCommand(sql, conn); OracleDataReader dr = cmd.ExecuteReader(); // C# if (dr.HasRows) { while (dr.Read()) { ifo.id = (int)dr["iid"]; ifo.name = dr["iname"].ToString(); ifo.idcardnum = dr["idcardnum"].ToString(); ifo.phonenum = dr["phonenum"].ToString(); ifo.address = dr["address"].ToString(); ifo.sex = dr["sex"].ToString()[0]; ifo.age = (int)dr["age"]; ifo.email = dr["email"].ToString(); } } else { throw new Exception("未能读取到相应的信息"); } } catch (Exception ex) { Console.Write(ex.Message); } finally { conn.Clone(); } return(ifo); }
Question IDataPumpSearchQueManager.FindOneQuestion(int qId)//参数为问题的编码(key),返回该问题所有内容 { OracleConnection conn = new OracleConnection(); Question temp_que = new Question(); try { //conn.ConnectionString = ConfigurationManager.ConnectionStrings["oradb"].ConnectionString; conn.ConnectionString = @"Data Source=(DESCRIPTION=(ADDRESS_LIST=(ADDRESS=(PROTOCOL=TCP)(HOST=59.110.237.142)(PORT=1521)))(CONNECT_DATA=(sid =lwhy)));User Id=lwhy;Password=123"; conn.Open(); string sql = " select * from QUESTION where qid = " + qId; // C# OracleCommand cmd = new OracleCommand(sql, conn); OracleDataReader dr = cmd.ExecuteReader(); // C# if (dr.HasRows) { while (dr.Read()) { temp_que.questionId = (int)dr["qid"]; temp_que.title = dr["title"].ToString(); temp_que.body = dr["body"].ToString(); temp_que.answer = dr["answer"].ToString(); temp_que.tags = dr["tags"].ToString(); temp_que.type = dr["type"].ToString()[0];//这句之后要进行思考。 } } else { throw new Exception("未能读取到相应的问题"); } } catch (Exception ex) { Console.Write(ex.Message); } finally { conn.Clone(); } return(temp_que); }
bool IDataPumpRegisterManager.checkName(string _name) { OracleConnection conn = new OracleConnection(); bool temp_isExist = false; try { //conn.ConnectionString = ConfigurationManager.ConnectionStrings["oradb"].ConnectionString; conn.ConnectionString = @"Data Source=(DESCRIPTION=(ADDRESS_LIST=(ADDRESS=(PROTOCOL=TCP)(HOST=59.110.237.142)(PORT=1521)))(CONNECT_DATA=(sid =lwhy)));User Id=lwhy;Password=123"; conn.Open(); string sql = " select * from IUSER where unickname = " + "\'" + _name + "\'"; // C# OracleCommand cmd = new OracleCommand(sql, conn); OracleDataReader dr = cmd.ExecuteReader(); // C# if (dr.HasRows) { while (dr.Read()) { String temp_nickname = dr["unickname"].ToString(); if (temp_nickname == _name) { temp_isExist = true; } else { throw new Exception("未知错误,代号DPRM"); } } } else { temp_isExist = false; } } catch (Exception ex) { } finally { conn.Clone(); } return(temp_isExist); }//用户名是否存在
List <Classification> SetOfClassification() { OracleConnection conn = new OracleConnection(); List <Classification> temp_lCla = new List <Classification>(); try { //conn.ConnectionString = ConfigurationManager.ConnectionStrings["oradb"].ConnectionString; conn.ConnectionString = @"Data Source=(DESCRIPTION=(ADDRESS_LIST=(ADDRESS=(PROTOCOL=TCP)(HOST=59.110.237.142)(PORT=1521)))(CONNECT_DATA=(sid =lwhy)));User Id=lwhy;Password=123"; conn.Open(); string sql = " select * from CLASSIFICATION"; OracleCommand cmd = new OracleCommand(sql, conn); OracleDataReader dr = cmd.ExecuteReader(); // C# if (dr.HasRows) { while (dr.Read()) { Classification temp_cla = new Classification(); temp_cla.cId = (int)dr[""]; temp_cla.Cla[0] = dr[""].ToString(); temp_cla.Cla[1] = dr[""].ToString(); temp_cla.Cla[2] = dr[""].ToString(); temp_cla.Cla[3] = dr[""].ToString(); temp_cla.Cla[4] = dr[""].ToString(); temp_lCla.Add(temp_cla); } } else { throw new Exception("未能读取到相应的问题"); } } catch (Exception ex) { } finally { conn.Clone(); } return(temp_lCla); }
private void button3_Click(object sender, EventArgs e) { try { string sql = "select * from PRODUCTS"; OracleCommand cmd = new OracleCommand(sql, conn); OracleDataAdapter pAdap = new OracleDataAdapter(); pAdap.SelectCommand = cmd; DataSet ds = new DataSet("dsCust"); pAdap.Fill(ds); dataGridView1.DataSource = ds.Tables[0]; conn.Clone(); } catch (Exception ex) { MessageBox.Show(ex.Message.ToString()); } }
private bool isRegulated() { if (username.Trim().Length == 0) { MessageBox.Show("Username is empty!"); return(false); } if (password.Trim().Length == 0 || repPassword.Trim().Length == 0) { MessageBox.Show("One of the password fields is empty!"); return(false); } if (!password.Equals(repPassword)) { MessageBox.Show("Passwords do not match."); return(false); } username = username.Trim(); using (OracleConnection conn = new OracleConnection(FormLogin.connString)) // using avtomatski ja zatvora otvorenata konekcija { conn.Open(); // mozhebi bi bilo podobro da se realizira so funkcija na nivo na baza string query = "SELECT COUNT(*) FROM Tipster WHERE UPPER(username) LIKE '" + username.ToUpper() + "'"; OracleCommand commCheck = new OracleCommand(query, conn); commCheck.CommandType = CommandType.Text; Object o = commCheck.ExecuteScalar(); int numRows = Int32.Parse(o.ToString()); if (numRows != 0) { MessageBox.Show("Already exists tipster with that username."); conn.Clone(); // za sekoj slucaj return(false); } } return(true); }
public void FiltrarFLujoTarea() { Conexion conexion = new Conexion(); OracleConnection conn = new OracleConnection(); conn = conexion.getConn(); conn.Open(); OracleCommand comando = new OracleCommand("SELECT * FROM FLUJO_TAREA WHERE ID_FLUJO_TAREA = '" + TXTBuscar.Text + "'", conn); OracleDataAdapter da = new OracleDataAdapter(comando); DataSet ds = new DataSet(); da.Fill(ds); conn.Clone(); GridFlujoTarea.DataSource = ds; GridFlujoTarea.DataBind(); }
public DataSet consultar(string consultaSQL) { Controlador.Conexion conexion = new Controlador.Conexion(); OracleConnection conn = new OracleConnection(); conn = conexion.getConn(); conn.Open(); OracleCommand comando = new OracleCommand(consultaSQL, conn); OracleDataAdapter da = new OracleDataAdapter(comando); DataSet ds = new DataSet(); da.Fill(ds); conn.Clone(); return(ds); }
/// <summary> /// 执行sql获取数据 /// </summary> /// <param name="query"></param> /// <param name="parameters"></param> /// <returns></returns> public OracleDataReader ExecuteReader(string query, OracleParameter[] parameters, CommandType type) { OracleConnection conn = GetConnection(); try { using (OracleCommand cmd = new OracleCommand(query, conn)) { cmd.CommandType = type; cmd.AddToStatementCache = true; cmd.BindByName = true; cmd.InitialLOBFetchSize = blobSize; if (parameters != null) { foreach (OracleParameter p in parameters) { cmd.Parameters.Add(p); } } //备注:连接关闭后,Reader读取数据将报错. if (MyTransactionScopeOld.Current == null) { return(cmd.ExecuteReader(CommandBehavior.CloseConnection)); //关闭Reader时,一并关闭连接. } else { return(cmd.ExecuteReader()); } } } catch (Exception ex) { if (conn != null && MyTransactionScopeOld.Current == null) { conn.Clone(); conn.Dispose(); } HandleOraException(ex as OracleException, conn); throw ex; } }