public DataSet getData(SqlConnection conn, SqlDataAdapter da, DataSet ds)
        {
            //don't forget to escape slashes
            string connString = "Data Source=.\\SQLEXPRESS;AttachDbFilename=C:\\PROG34998\\finalProject\\Project1\\Store.mdf;Integrated Security=True;User Instance=True";
            try
            {
                conn = new SqlConnection(connString);
                conn.Open();

                string sql = "SELECT * FROM [tCustomer]";
                da = new SqlDataAdapter(sql, conn);

                ds = new DataSet();
                da.Fill(ds, "tCustomer");
                conn.Close();

            }
            catch (SqlException ex)
            {
                if (conn != null)
                {
                    conn.Close();
                }
                MessageBox.Show(ex.Message, "Error Retrieving from DataBase");
            }

            return ds;
        }
Example #2
0
        protected void Booking_DeleteCommand(object source, DataListCommandEventArgs e)
        {
            int bookingid;
            bookingid = Convert.ToInt32(e.CommandArgument);

            SqlConnection con = new SqlConnection(strconn);
            con.Open();

            SqlCommand cmd = new SqlCommand("Delete from schedule where id = '" + bookingid + "'", con);
            SqlCommand cmd2 = new SqlCommand("UPDATE  carOwner  SET   MyPoints =  MyPoints+200   where carOwner.ownerID = (Select schedule.OwnerID from schedule where id = '" + bookingid + "')", con);

            int res2 = cmd2.ExecuteNonQuery();
            int res = cmd.ExecuteNonQuery();
            if (res > 0 && res2 > 0)
            {
                Label5.Visible = true;
                Label5.Text = "Your booking has been cancelled and you have been refunded back with 200 points";
                con.Close();
            }
            else
            {
                Label5.Visible = true;
                Label5.Text = "Error in booking cancelling try again later";
                con.Close();
            }

            displayBooking();
        }
        protected void Load_Grid()
        {
            string connectionString;
            connectionString = ConfigurationManager.ConnectionStrings["conStr"].ToString();

            SqlConnection con = new SqlConnection(connectionString);

            try
            {
                con.Open();
            }
            catch (Exception)
            {
                con.Close();
                return;
                throw;
            }

            SqlCommand cmd = new SqlCommand("SELECT C.*, A.agent_name FROM Customers AS C INNER JOIN Users AS U ON C.user_id = U.user_id INNER JOIN Employees AS E ON E.user_id = U.user_id INNER JOIN Agents AS A ON A.agent_id = E.agent_id", con);
            SqlDataReader dr = cmd.ExecuteReader();
            DataTable tablo = new DataTable();
            tablo.Load(dr);

            CustomerGrid.DataSource = tablo.DefaultView;
            CustomerGrid.DataBind();

            dr.Close();
            con.Close();
        }
Example #4
0
        /// <summary>
        /// 执行SQL语句返回影响的行数
        /// </summary>
        /// <param name="cmdText">SQL文本</param>
        /// <returns>影响行数</returns>
        public static int ExecuteNonQuery(string cmdText)
        {
            int retVal = 0;
            SqlConnection conn = new SqlConnection(ConnectionString);
            SqlCommand comm = new SqlCommand();

            try
            {
                if (conn.State != ConnectionState.Open)
                {
                    conn.Open();
                }

                comm.Connection = conn;
                comm.CommandText = cmdText;
                comm.CommandTimeout = 600;
                retVal = comm.ExecuteNonQuery();
                if (conn.State != ConnectionState.Closed)
                {
                    conn.Close();
                }

                return retVal;
            }
            catch
            {
                conn.Close();
                throw;
            }
        }
 public requirements Insert(requirements id)
 {
     string ConnectionString = IDManager.connection();
     SqlConnection con = new SqlConnection(ConnectionString);
     try
     {
     con.Open();
     SqlCommand cmd = new SqlCommand("SP_DMCS_INSERT_REQUIREMENTS", con);
     cmd.CommandType = System.Data.CommandType.StoredProcedure;
     cmd.Parameters.AddWithValue("@requirement_desc", id.requirement_desc);
     cmd.ExecuteReader();
     con.Close();
     con.Open();
     cmd = new SqlCommand("SP_DMCS_GET_REQUIREMENTS", con);
     cmd.CommandType = System.Data.CommandType.StoredProcedure;
     cmd.Parameters.AddWithValue("@requirement_desc", id.requirement_desc);
     SqlDataReader rdr = cmd.ExecuteReader();
     if (rdr.HasRows)
     {
         rdr.Read();
         id.req_id = rdr.GetInt32(0);
     }
     }
     catch (Exception ex)
     {
     id.SetColumnDefaults();
     }
     finally
     {
     con.Close();
     }
     return id;
 }
Example #6
0
        protected long Execute(string procName, SqlParameter[] param)
        {
            long retVal = -1;
            SqlConnection con = new SqlConnection(GetConnection());
            SqlCommand cmd = null;
            try
            {

                con.Open();
                cmd = new SqlCommand();
                cmd.CommandText = procName;
                cmd.CommandType = CommandType.StoredProcedure;
                cmd.Parameters.AddRange(param);
                cmd.Connection = con;
                retVal = cmd.ExecuteNonQuery();
                con.Close();
            }
            catch (Exception)
            {
                if (cmd != null)
                {
                    cmd.Dispose();
                    con.Close();
                }
            }
            return retVal;
        }
Example #7
0
 /// <summary>
 /// Panels the type identifier.
 /// </summary>
 /// <param name="panelTypeCode">The panel type code.</param>
 /// <returns></returns>
 
 public int PanelTypeId(string panelTypeCode)
 {
     var panelTypeId = 1;
     using (var con = new SqlConnection(Properties.Settings.Default.ConnectionToSQL))
     {
         try
         {
             con.Open();
             var sqlCommand =
                 new SqlCommand(@"SELECT *  FROM [AirVents].[PanelType] WHERE[PanelTypeCode]   = '" + panelTypeCode + "'", con);
             var sqlDataAdapter = new SqlDataAdapter(sqlCommand);
             var dataTable = new DataTable("panelTypeName");
             sqlDataAdapter.Fill(dataTable);
             panelTypeId =  Convert.ToInt32(dataTable.Rows[0]["PanelTypeID"]);
         }
         catch (Exception)
         {
             con.Close();
         }
         finally
         {
             con.Close();
         }
     }
     return panelTypeId;
 }
        private void button11_Click(object sender, EventArgs e)
        {
            string con = "server=Crazyboy-PC;Initial Catalog=master;Integrated Security=SSPI";
            string sql = "select Cbill,Cstyle,Csum,Ctime,CID,Gno from cash where Ctime='" + dateTimePicker2.Text.ToString() + "'";
            SqlConnection mycon = new SqlConnection(con);
            SqlCommand cmd = new SqlCommand(sql, mycon);
            if (mycon.State == ConnectionState.Closed)
                mycon.Open();
            SqlDataReader dr = cmd.ExecuteReader();
            dataGridView1.DataSource = 0;
            if (dr.HasRows)
            {
                BindingSource bs = new BindingSource();
                bs.DataSource = dr;
                this.dataGridView1.DataSource = bs;
                dataGridView1.Columns[0].HeaderCell.Value = "账单号";
                dataGridView1.Columns[1].HeaderCell.Value = "消费类型";
                dataGridView1.Columns[2].HeaderCell.Value = "消费金额";
                dataGridView1.Columns[3].HeaderCell.Value = "消费时间";
                dataGridView1.Columns[4].HeaderCell.Value = "收银员";
                dataGridView1.Columns[5].HeaderCell.Value = "客房号";
            }

            mycon.Close();

            //关闭连接并释放资源
            if (ConnectionState.Open == mycon.State)
            {
                mycon.Close();
            }
            mycon.Dispose();
        }
Example #9
0
        protected void ButtonEnviar_Click(object sender, EventArgs e)
        {
            try
            {
                SqlConnection conn = new SqlConnection(ConfigurationManager.ConnectionStrings["RegistroConnectionString"].ConnectionString);
                conn.Open();
                String contar_mensajes = "select count(*) from Mensaje_privado";
                SqlCommand command = new SqlCommand(contar_mensajes, conn);
                int contador = Convert.ToInt32(command.ExecuteScalar().ToString());
                conn.Close();

                conn.Open();
                String enviar_mensaje = "insert into Mensaje_privado (id_mensaje, id_remitente, id_buzon, leido, mensaje, asunto, fecha_de_envio) values (" + contador + ", " + Bandeja_Entrada.id_usuario + ", " + Bandeja_Entrada.id_destino + ", " + 0 + ", '" + TextBoxEM.Text + "', '" + LabelAsunto.Text + "', CURRENT_TIMESTAMP)";
                command = new SqlCommand(enviar_mensaje, conn);
                command.ExecuteNonQuery();
                Response.Write("Mensaje enviado!");
                Panel1.Visible = false;
                ButtonVolver.Visible = true;

                conn.Close();
            }
            catch (Exception ex)
            {
            }
        }
Example #10
0
        /// <summary>
        /// Performs a scalar select and returns the value as a string
        /// </summary>
        /// <param name="qS"></param>
        /// <returns></returns>
        public static String ScalarString(String qS)
        {
            object returnValue = "";
            SqlConnection con = new SqlConnection(ConnectionString);
            SqlCommand cmd = new SqlCommand(qS, con);

            using (con)
            {
                if (con.State == ConnectionState.Open)
                {
                    returnValue = cmd.ExecuteScalar();
                    con.Close();
                }
                else
                {
                    con.Open();
                    returnValue = cmd.ExecuteScalar();
                    con.Close();
                }
            }

            if (returnValue == null)
            {
                return "";
            }
            else
                return returnValue.ToString();
        }
Example #11
0
 public List<ItemTarefa> buscaItensTarefa(int id)
 {
     List<ItemTarefa> listaItens = new List<ItemTarefa>();
     SqlConnection conexao = new SqlConnection();
     conexao.ConnectionString = StaticObjects.strConexao;
     SqlCommand comando = new SqlCommand();
     SqlDataReader leitor;
     try
     {
         conexao.Open();
         comando.CommandText = @"SELECT id,idTarefa,data,descricao FROM dbo.ItensTarefa WHERE idTarefa = " + id + " ";
         comando.Connection = conexao;
         leitor = comando.ExecuteReader();
         while (leitor.Read())
         {
             ItemTarefa it = new ItemTarefa();
             it.id = Convert.ToInt16(leitor["id"]);
             it.idTarefa = Convert.ToInt16(leitor["idTarefa"]);
             it.data = Convert.ToDateTime(leitor["data"]);
             it.descricao = leitor["descricao"].ToString();
             listaItens.Add(it);
         }
         conexao.Close();
         return listaItens;
     }
     catch (Exception)
     {
         conexao.Close();
         return null;
     }
 }
Example #12
0
        public Task Send(Message[] messages)
        {
            if (messages == null || messages.Length == 0)
            {
                return TaskAsyncHelper.Empty;
            }

            SqlConnection connection = null;
            try
            {
                connection = new SqlConnection(_connectionString);
                connection.Open();
                using (var cmd = new SqlCommand(_insertSql, connection))
                {
                    cmd.Parameters.AddWithValue("Payload", JsonConvert.SerializeObject(messages));

                    return cmd.ExecuteNonQueryAsync()
                        .Then(() => connection.Close()) // close the connection if successful
                        .Catch(ex => connection.Close()); // close the connection if it explodes
                }
            }
            catch (SqlException)
            {
                if (connection != null && connection.State != ConnectionState.Closed)
                {
                    connection.Close();
                }
                throw;
            }
        }
Example #13
0
 public bool AddProduct(ProductsDto productsDto)
 {
     var cn = new SqlConnection(GetConnection());
     SqlTransaction trx = null;
     var isInsert = false;
     try
     {
         cn.Open();
         trx = cn.BeginTransaction();
         string cmdText = " insert into Products(ProductName,ProductCategory,MemberAnaylst,OrganizationName,TenureId,StyleResearchId,StrategyId,FrequencyCall,FrequencyCallType,Logo,CreateUserId,CreateTimeStamp,ModifiedUserId,ModifiedTimeStamp) " +
                          "values('" + productsDto.ProductName + "'," + productsDto.ProductCategory + "," + productsDto.MemberAnaylst + ",'" + productsDto.OrganizationName + "'," + productsDto.TenureId + "," + productsDto.StyleResearchId + "," + productsDto.StrategyId + "," + productsDto.FrequencyCall + ",'" + productsDto.FrequencyCallType + "','" + productsDto.Logo + "'," + productsDto.CreateUserId + ", '" + DateTime.Now.ToString("yyyy-MM-dd") + "'," + productsDto.ModifiedUserId + ",'" + DateTime.Now.ToString("yyyy-MM-dd") + "') select Scope_Identity();";
         var cmd = new SqlCommand(cmdText, cn) { Transaction = trx };
         var productId = Convert.ToInt32(cmd.ExecuteScalar());
         foreach (var documents in productsDto.ProductDocumentDtos)
             (new SqlCommand("insert into ProductDocument(ProductId,FileName,DocumentName) values( " + productId + ",'" + documents.FileName + "','" + documents.DocumentName + "')", cn) { Transaction = trx }).ExecuteNonQuery();
         trx.Commit();
         isInsert = true;
         cn.Close();
     }
     catch (Exception)
     {
         if (trx != null) trx.Rollback();
         cn.Close();
     }
     return isInsert;
 }
        private void TryDBConnect()
        {
            bool IsConnect = false;

            string connectionString = System.Configuration.ConfigurationManager.ConnectionStrings["strCon"].ConnectionString;
            SqlConnection connection = new SqlConnection(connectionString);

            XLog.Write("正在连接数据库...");
            try
            {
                connection.Open();
                if (connection.State == ConnectionState.Open)
                {
                    IsConnect = true;
                }
                connection.Close();
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message);
                IsConnect = false;
                connection.Close();
            }

            if (IsConnect == false)
            {
                DialogResult result = MessageBox.Show("无法连接至数据库服务器,请确认配置是否正确,网络是否畅通?", "无法连接至数据库服务器...", MessageBoxButtons.RetryCancel, MessageBoxIcon.Warning);
                if (result == DialogResult.Retry)
                {
                    TryDBConnect();
                }
            }
        }
Example #15
0
        public string insertandUpdate( string commandString)
        {
            string result = null; ;
            string connectonString = System.Web.Configuration.WebConfigurationManager.ConnectionStrings["ConnectionString"].ToString();
              //  string commandString = String.Format("SELECT username FROM t_user where username='{0}'", username);
            SqlConnection sqlConnection = new SqlConnection(connectonString);
            try
            {
                sqlConnection.Open();
                SqlCommand command = new SqlCommand();
                command.Connection = sqlConnection;
                command.CommandText = commandString;
                int num = command.ExecuteNonQuery();
                if (num>0)
                result = "[email protected]执行成功";
                else
                    result = "[email protected]未找到值";
                sqlConnection.Close();

            }
            catch (Exception e)
            {
                result = "[email protected]" + e.Message;
            }
            finally
            {
                sqlConnection.Close();
            }

            return result;
        }
Example #16
0
        public static Boolean delete_rams(string strConnDB, string txt_week)
        {
            SqlConnection objConn = new SqlConnection();
            objConn.ConnectionString = strConnDB;
            objConn.Open();
            try
            {
                SqlCommand cmd_rams_delete = new SqlCommand("usp_BH_RAMS_Delete", objConn);
                cmd_rams_delete.CommandTimeout = 0;
                cmd_rams_delete.CommandType = CommandType.StoredProcedure;
                cmd_rams_delete.Parameters.Add("@Week", SqlDbType.VarChar).Value = txt_week;
                cmd_rams_delete.ExecuteNonQuery();

                objConn.Close();
                objConn = null;
                return true;
            }
            catch (Exception ex)
            {
                objConn.Close();
                objConn = null;
                PrimaryHaul_WS.PH_ExceptionManager.WriteError(ex.Message);
                return false;
            }
        }
Example #17
0
 public static DataTable ExecuteData(CommandType cmdCommandType, string cmdCommandString, params SqlParameter[] cmdParameters)
 {
     SqlCommand cmdCommand = new SqlCommand();
     SqlConnection connect = new SqlConnection(ConnectionString.Text);
     try
     {
         DataTable dattTopic = new DataTable();
         SqlDataAdapter dataTopic = new SqlDataAdapter(cmdCommand);
         PrepareCommand(cmdCommand, connect, null, cmdCommandType, cmdCommandString, cmdParameters);
         cmdCommand.ExecuteNonQuery();
         dataTopic.Fill(dattTopic);
         cmdCommand.Parameters.Clear();
         if (connect.State == ConnectionState.Open) connect.Close();
         return dattTopic;
     }
     catch (SqlException ex)
     {
         if (connect.State == ConnectionState.Open)
         {
             connect.Close();
             SqlConnection.ClearPool(connect);
         }
         throw ex;
     }
 }
Example #18
0
 public void Delete(DataGridView dataGridView1)
 {
     connect = DataBaseConnection.getInstance().getConnect();
     try
     {
         foreach (DataGridViewRow item in dataGridView1.Rows)
         {
             if ((bool)item.Cells[0].Value)
             {
                 connect.Open();
                 SqlCommand cmd = new SqlCommand("delete from [Table] where Name = '"+item.Cells[1].Value.ToString()+"'", connect);
                 cmd.ExecuteNonQuery();
                 connect.Close();
                // dataGridView1.Rows.Remove(item);
                 ShowMessages.PutMessageInContainer("Delete Operation  was succeeded", Color.Tomato);
             }
         }
         MessageBox.Show("SuccessFully Deleted ..!");
         dataGridView1.Rows.Clear();
         update(dataGridView1);
     }
     catch (Exception EX)
     {
         MessageBox.Show(EX.StackTrace.ToString(), "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
         ShowMessages.PutMessageInContainer("Error within Delete Operation ", Color.Red);
     }
     finally
     {
         connect.Close();
     }
 }
 public bool Eliminar(string empresaid, DataTable TablaTrab)
 {
     using (SqlConnection cnx = new SqlConnection(conex.empConexion(empresaid)))
     {
         bool xreturn = true;
         int lcont = 0;
         for (lcont = 0; lcont <= TablaTrab.Rows.Count - 1; lcont++)
         {
             using (SqlCommand cmd = new SqlCommand("gspTbPllaCargos_ELIMINAR", cnx))
             {
                 cmd.CommandTimeout = 0;
                 cmd.CommandType = CommandType.StoredProcedure;
                 cmd.Parameters.Add("@cencosid", SqlDbType.Char, 5).Value = TablaTrab.Rows[lcont]["cencosid"];
                 cmd.Parameters.Add("@cargoid", SqlDbType.Char, 3).Value = TablaTrab.Rows[lcont]["cargoid"];
                 try
                 {
                     cnx.Open();
                     if (cmd.ExecuteNonQuery() > 0)
                     { xreturn = true; }
                     else
                     { xreturn = false; }
                     cnx.Close();
                 }
                 catch (Exception ex)
                 {
                     Sql_Error = ex.Message;
                     //throw new Exception(ex.Message);
                     xreturn = false;
                     cnx.Close();
                 }
             }
         }
         return xreturn;
     }
 }
Example #20
0
        public static object ReturnValueFromTable(string NomeTabella, string NomeColonna,string Where)
        {
            string sSQL = "SELECT " + NomeColonna + " FROM " + NomeTabella + " WHERE " + Where;
            SqlConnection objCN = new SqlConnection(cnnStringSettings);
            SqlDataReader dr = null;
            try
            {
                SqlCommand cmd = new SqlCommand(sSQL, objCN);
                objCN.Open();
                dr = cmd.ExecuteReader();
                object objValue = -1;
                while (dr.Read())
                {
                    objValue = dr[NomeColonna];
                }
                dr.Close();
                objCN.Close();
                return objValue;
            }
            catch
            {
                if (!dr.IsClosed)
                    dr.Close();
                objCN.Close();
                return null;
            }

        }
Example #21
0
        public bool checkMail(string email, int type)
        {
            string query = "";
            SqlConnection con = new SqlConnection(connectionString);
            try
            {
                con.Open();
                if (type == 1)
                    query = "SELECT teacher_email FROM Teachers WHERE teacher_email = '" + email + "';";
                else // student
                    query = "SELECT student_email FROM Students WHERE student_email = '" + email + "';";
                SqlCommand command = new SqlCommand(query, con);

                SqlDataReader reader = command.ExecuteReader();
                // check how many rows the sql query found
                if (reader.HasRows == true)
                {
                    return true;
                }
                con.Close();
            }
            catch (Exception ex)
            {
                throw ex;
            }
            finally
            {
                con.Close();
            }
            return false;
        }
Example #22
0
        public void ExecuteCommand(string sqlstr)
        {
            string connectionString;
            connectionString = ConfigurationManager.ConnectionStrings["conStr"].ToString();

            SqlConnection con = new SqlConnection(connectionString);

            try
            {
                con.Open();
            }
            catch (Exception)
            {
                con.Close();
                throw;
            }

            try
            {
                SqlCommand command = new SqlCommand(sqlstr, con);
                command.ExecuteNonQuery();
                con.Close();
            }
            catch (Exception)
            {
                con.Close();
                throw;
            }
        }
Example #23
0
    public static string ConfirmQrCode(int qrCode, string newUserOpenId)
    {
        string originalUserOpenId = "";
        SqlConnection conn = new SqlConnection(System.Configuration.ConfigurationSettings.AppSettings["constr"].Trim());
        SqlCommand cmd = new SqlCommand(" select qr_invite_list_owner from qr_invite_list where qr_invite_list_id = " + qrCode.ToString(), conn);
        conn.Open();
        SqlDataReader drd = cmd.ExecuteReader();
        if (drd.Read())
        {
            originalUserOpenId = drd.GetString(0);
        }
        drd.Close();
        conn.Close();
        cmd.CommandText = " insert into qr_invite_list_detail ( qr_invite_list_detail_id , qr_invite_list_detail_openid ) "
            + " values ('" + qrCode.ToString() + "' , '" + newUserOpenId.Replace("'", "").Trim() + "' ) ";
        conn.Open();
        try
        {
            cmd.ExecuteNonQuery();
        }
        catch
        {

        }
        conn.Close();
        return originalUserOpenId.Trim();
    }
Example #24
0
    public string log(string uname, string pwd)
    {
        //if (uname == "admin" && pwd == "admin")
        //{
        //    return "success";
        //}
        //else
        //{
        //    return "fail";
        //}

        SqlConnection conn = new SqlConnection(ConfigurationManager.ConnectionStrings["dbString"].ConnectionString);
        conn.Open();
        SqlCommand cmd = new SqlCommand("Select * from Table2 where Userid='" + uname + "' AND Password = '" + pwd + "' ", conn);
        SqlDataReader data = null;
        data = cmd.ExecuteReader();
        if (data.HasRows)
        {
            data.Dispose();
            cmd.Dispose();
            conn.Close(); return "Y";
        }
        else
        {
            data.Dispose();
            cmd.Dispose();
            conn.Close(); return "N";
        }
    }
Example #25
0
        public void ProcessRequest(HttpContext context)
        {
            context.Response.ContentType = "text/plain";
            string flag = context.Request["flag"].ToString();
            string struid = context.Session["ID"].ToString();
            string strSQL = "update dbo.tabUsers set ";
            string strDataConn = ConfigurationManager.ConnectionStrings["SQLDataConnStr"].ConnectionString;
            SqlConnection dataConn = new SqlConnection(strDataConn);

            if (flag == "1")
            {
                string strusername = context.Request["username"].ToString();
                string strutell = context.Request["utell"].ToString();
                string struemail = context.Request["uemail"].ToString();
                strSQL += "UserName = '" + strusername + "',"+" UserTel = '"+strutell+"',"+"UserEmail = '"+struemail+"' where ID = '"+struid+"'";
                SqlCommand command = new SqlCommand(strSQL, dataConn);
                dataConn.Open();
                command.ExecuteNonQuery();
                dataConn.Close();
                context.Response.Write("OK");
            }
            else if (flag == "2")
            {
                string strpw = context.Request["upassword"].ToString();
                strSQL +=  "UserPW = '" + strpw + "' where UserID = '" + struid + "'";
                SqlCommand command = new SqlCommand(strSQL, dataConn);
                dataConn.Open();
                command.ExecuteNonQuery();
                dataConn.Close();
                context.Response.Write("OK");
            }
        }
Example #26
0
    protected void btnBookFlight_Click(object sender, EventArgs e)
    {
        SqlConnection objCon = new SqlConnection(strCon);

        try
        {
            objCon.ConnectionString = strCon;
            objCon.Open();
        }
        catch (Exception ex)
        {
            this.lblConnect.Text = "Unable to connect to database.";
        }

        if (objCon.State == System.Data.ConnectionState.Open)
        {
            InsertFlightInfo();
            InsertFlightOrder();

            objCon.Close();
            objCon.Dispose();
        }
        else
        {
            lblConnect.Text = "Unable to connect to database.";
            objCon.Close();
            objCon.Dispose();

        }
        objCon.Close();
        objCon.Dispose();

        redirectToNextPage();
    }
 private void loginbutton_Click(object sender, EventArgs e)
 {
     string sqlconnstr = "Data Source=" + addersstextbox.Text + ";uid=" + accounttextbox.Text +
         ";pwd=" + pwdtextbox.Text + ";Initial Catalog="+DBNameBox.Text+";";
     SqlConnection SqlConn = new SqlConnection(sqlconnstr);
     if (SqlConn.State == ConnectionState.Open)
     {
         SqlConn.Close();
     }
     try
     {
         SqlConn.Open();
     }
     catch (Exception ex)
     {
         System.Windows.Forms.MessageBox.Show(ex.Message);
     }
     if (SqlConn.State == ConnectionState.Open)
     {
         SqlConn.Close();
         MainForm dm = new MainForm(SqlConn);
         dm.Show();
         this.Hide();
     }
 }
    private void LoadProviders()
    {
        Connection = new SqlConnection(ConnectionString);
        DataTable dt = new DataTable();
        try
        {
            command = new SqlCommand();
            command.CommandType = CommandType.Text;
            command.Connection = Connection;
            Connection.Open();
            command.CommandText = "SELECT * FROM tbl_API_Providers where provider_status=1";
            SqlDataAdapter da = new SqlDataAdapter(command);
            da.Fill(dt);
            Connection.Close();
        }
        catch (Exception ex)
        {
            //to do
            //Log Exception
        }
        finally
        {
            if (Connection.State == ConnectionState.Open)
                Connection.Close();
        }

        ddlProviders.DataSource = dt;
        ddlProviders.DataTextField = "Provider_Name";
        ddlProviders.DataValueField = "Provider_ID";
        ddlProviders.DataBind();
        ddlProviders.Items.Insert(0, new ListItem("Please select", "0"));
    }
Example #29
0
    protected void Button1_Click(object sender, EventArgs e)
    {
        Label1.Text = Server.HtmlEncode(this.elm1.Value);
        //Label1.Text = this.elm1.Value;

        //String QueryString = "INSERT INTO Article (Id, auteur, date, categorie) VALUES ('7', 'FCW', '', 'Informatique')";

        String QueryString = "INSERT INTO Article_Blog (ID, Auteur, Content, Tag) VALUES ('" + TextBox1.Text + "', '" + TextBox2.Text + "',  '" + this.elm1.Value + "','" + TextBox3.Text + "')";
        SqlConnection Cn = new SqlConnection("server=WAZZUP-PC\\SQLEXPRESS; initial catalog=TestDB; integrated security=true");

        try
        {

            Cn.Open();
            if (Cn != null)
            {
                Label1.Text = "CONNECTER";
                Console.WriteLine("CONNECTER");
            }

            SqlCommand Cmd = new SqlCommand();
            Cmd.CommandText = QueryString;
            //Cmd.CommandType = CommandType.Text;
            Cmd.Connection = Cn;

            Cmd.ExecuteNonQuery();

            Cn.Close();
        }
        catch (Exception Ex)
        {
            Label1.Text = Ex.ToString();
            Cn.Close();
        };
    }
Example #30
0
        private void onload()
        {
            string strSQLconnection = @"Data Source=(LocalDb)\v11.0;AttachDbFilename=|DataDirectory|\aviation.mdf; Trusted_Connection=True;User Instance=True";
            SqlConnection sqlConnection = new SqlConnection(strSQLconnection);
            SqlCommand sqlCommand = new SqlCommand("SELECT p.username,p.nama,p.jawatan,p.bahagian,p.telefon_bimbit,p.telefon_pejabat,p.email FROM profil_pegawai p, supervisor s WHERE p.username = s.ic ORDER BY p.nama", sqlConnection);

                try
                {
                    if (sqlConnection.State.Equals(ConnectionState.Open))
                        sqlConnection.Close();

                    if (sqlConnection.State.Equals(ConnectionState.Closed))
                        sqlConnection.Open();

                    SqlDataAdapter mySqlAdapter = new SqlDataAdapter(sqlCommand);
                    DataSet myDataSet = new DataSet();
                    mySqlAdapter.Fill(myDataSet);

                    gridpenyelia.DataSource = myDataSet;
                    gridpenyelia.DataBind();

                    if (sqlConnection.State.Equals(ConnectionState.Open))
                        sqlConnection.Close();

                    if (sqlConnection.State.Equals(ConnectionState.Closed))
                        sqlConnection.Open();
                }
                catch (SqlException ex)
                {
                }
                finally
                {

                }
        }