C # – Update the database and use data table and data adapter

What's up with the following code? The database is not updated and otherwise {} will always be executed. The database contains 1 line with the field Password!

    protected void Button1_Click(object sender, EventArgs e)
    {

            string connectionString = @"Data Source = (localdb)MSSQLLocalDB; Initial Catalog = db1; Integrated Security = True";
            SqlConnection cnn = new SqlConnection(connectionString);
            String sql = "update table1 set password = 'hello'";
            SqlCommand command = new SqlCommand(sql, cnn);
        SqlDataAdapter da = new SqlDataAdapter(command);
            DataTable dt = new DataTable();
            da.Fill(dt);
        cnn.Open();
        command.ExecuteNonQuery();
            cnn.Close();
            if (dt.Rows.Count > 1)
            {
                ScriptManager.RegisterClientScriptBlock(this, this.GetType(), "alertMessage", "alert('Password Reset Successful! Redirecting to Homepage!')", true);
                Response.Redirect("testlogin.aspx");
            }
            else
            {
                Label1.Text = "Invalid Details";
            }

    }

postgresql – How do I avoid multiple SELECTs from a property table? 

I have a table of key-value pairs for managing user settings. This approach is referred to as a "pouch with properties". One of its advantages is that you don't need schema changes when a new property is required. Instead, you simply add a record to the properties table.

Now I need to get several properties within a function (or stored procedure). However, since the results are returned as multiple rows, I cannot take simple steps with this approach:

SELECT prop1, prop2 FROM settings;

The query returns multiple rows, so the results cannot be saved in local variables with the SELECT col INTO var Statement either. Yes, I can do two or more consecutive SELECTs, but this doesn't seem to be a particularly efficient and elegant solution:

SELECT value FROM settings WHERE key = ‘prop1’;
SELECT value FROM settings WHERE key = ‘prop2’;

A few ideas I've been thinking about:

FOR..IN loop

The function has OUT Parameters, in this case called prop1 (VARCHAR) and prop2 (BOOLEAN):

DECLARE
  settings_row RECORD;
BEGIN
  FOR settings_row IN
    SELECT key, value FROM settings
  LOOP
    CASE
      WHEN settings_row.key = 'prop1' THEN
        prop1 := settings_row.value::VARCHAR;
      WHEN settings_row.key = 'prop2' THEN
        prop2 := settings_row.value::BOOLEAN;
      -- more cases handled here in case you needed other properties
    END CASE;
  END LOOP;

  RETURN;
END;

Cross join

Link the settings table to itself and force the two properties to end up in columns. You might be able to live with it if you only need two properties, but for any other value that requires another cross connection, this doesn't seem to be a particularly scalable solution.

SELECT
  s1.value AS prop1, s2.value AS prop2
FROM settings s1
CROSS JOIN settings s2
WHERE
  s1.key = 'prop1' and s2.key = 'prop2';

php – How to insert forms from one table and insert the ID into another using the checkbox

Hello everyone, I'm something new in forms with PHP and database and I'm trying to use check boxes to select a product. I have 2 tables per call plenitud_productos and another one plenitud_pedidosSince the product table already contains records and prices, I only use them to print this data in the browser. This information is stored in the order table via a form, but with an additional column, namely "Quantity".

This way I print the names and prices. I have different names for this on the form and in the columns of the table in the database. These are:

Type = refers to the name of the product and donation = price.

                        
"> $

Problematic

1) If I want to use this form, I have to enter the quantity of the product in a text entry and the product via a checkbox, so when I select a product and write the quantity, or the number does not add anything in the table.

These are the insert queries I used:

This is the SQL error when I try to run the query on the database:

#1366 - Incorrect integer value: '$grupo' for column `plenitud_organizador`.`plenitud_pedidos`.`grupo` at row 1

Attached picture:
SQL column

How do I print a table with all iterations in Python?

With the following code I can only get the final answers. How do I print out each step?


def funcao_volume(x : float):
    return 4*(x**3) - 1014*(x**2) + 62370*x

def calculate_alpha(delta: float):
    numerador = delta*(5**(1/2) -1)
    return numerador/2

def calcuatex1(b : float, alph: float):
    return b - alph

def calcuatex2(a: float, alph: float):
    return a + alph

def abs(a:float, b:float):
    if a>b:
        return a - b
    else:
        return b - a

a = 0
b = 105
resp = list()
erro = 1
it = 1

#Iniciando o processo
while erro > 0.001 or len(resp) < 1000:
    delta = b - a
    alph = calculate_alpha(delta)
    x1 = calcuatex1(b,alph)
    x2 = calcuatex2(a,alph)
    v1 = funcao_volume(x1)
    v2 = funcao_volume(x2)
    if v1<=v2:
        a = x1
    else:
        b = x2
    erro = abs(a,b)
    it = it+1
    resp.append({"it": it, "erro":erro,"v1":v1,"v2":v2,"x1":x1,"x2":x2})

#printando o ultimo resultado
print (resp(-1))


SQL Server – How can I find out the name of the table in which the selection was made with C #?

I have a generic method that I use to run a query and get the returned columns dynamically. The purpose is clearly to be able to run any query without knowing the structure of the query as such:

 public async Task>> SelectFromDatabase(ConexionSQL con, string consulta)
        {


            List> resultados = new List>();



            try
            {
                using (var conexion = new SqlConnection("Server=" + con.Servidor + ";Initial Catalog=" + con.BD + ";User Id=" + con.Usuario + ";Password=" + con.Password + ";Persist Security Info=True;MultipleActiveResultSets=True;"))
                {

                    await conexion.OpenAsync();

                    using (var comando = new SqlCommand(consulta, conexion))
                    {
                        var reader = await comando.ExecuteReaderAsync();


                        foreach (var item in reader.Cast())
                        {
                            List columnas = new List();

                            for (int i = 0; i < item.FieldCount; i++)
                            {
                                if (item.GetValue(i) != null)
                                {

                                    var anonimo = new { columna = item.GetName(i), valor = item.GetValue(i) };


                                    columnas.Add(anonimo);
                                }
                            }

                            resultados.Add(columnas);
                        }

                    }
                }


                return resultados;

            }
            catch (Exception e)
            {
                List columnas = new List();

                var anonimo = new { columna = "error", valor = e.ToString() };

                columnas.Add(anonimo);

                resultados.Add(columnas);

                return resultados;
            }


        }

This works fine, but I would like to know if there is any way to get the name of the table where the query ran after it ran ??????

postgresql – Are there performance issues with inserting "COLLATE" as part of the query instead of setting it for the column / table?

Specifying the sort order in the table means that the "order by" or "group by" clause is used by default in this column, which saves some input

https://www.postgresql.org/docs/current/collation.html

Performance has no effect other than the speed difference between the different collations.

The data is not saved in this particular order. A major problem when setting collation for a column is deriving the collation

The collation derivation of an expression can be implicit or explicit. This distinction affects how collations are combined when several different collations are displayed in one printout. Explicit collation derivation occurs when a COLLATE clause is used. All other collation derivatives are implicit. If several collations have to be combined, for example in a function call, the following rules are used:

If an input expression has an explicit collation derivative, then all explicitly derived collations among the input expressions must be the same, otherwise an error is raised. If there is an explicitly derived collation, this is the result of the collation combination.

Otherwise, all input expressions must have the same implicit collation derivative or the standard collation. If there is a non-standard sort, it is the result of the sort combination. Otherwise the result is the standard collation.

If there are conflicting implicit non-standard collations between the input expressions, it is assumed that the combination has an undetermined collation. This is not an error condition unless the function called requires knowledge of the collation to be applied. In this case, an error is triggered at runtime.

There is one thing that is not documented or I cannot find anything.

I do not know what

create index 

works if a sort is defined for a column?

I assume that this compilation will be used, which raises another interesting question
What does it do if it is a composite index with different collations between the columns? I would follow the rules above.

postgresql – Recursively get a tree over a self-connected table

With other questions here and the Postgresql documentation, I managed to create a self-linked table with too many.

Add a WHERE Clause annoys me.

Problem:

ON Category can have many child categories and many parent categories. Accepted category.IdI want to get the category, the category kids, kids kids etc.

example: given this structure:

child_1
    child_11
        child_111
        child_112
            child_1121
    child_21
child_2

Given: a clause from id = child_11

Expected results:
child_11, child_111, child_112, child_1121.

Actual results: child_11, child_111, child_112

Here is my attempt: http://sqlfiddle.com/#!17/3640f/2

Note: I don't care if the where clause is duplicated. My application can handle it

Table structure:

CREATE TABLE Category(id SERIAL PRIMARY KEY, name VARCHAR(255));
CREATE TABLE Categories(parent_id INTEGER, child_id INTEGER, PRIMARY KEY(parent_id, child_id));

ALTER TABLE Categories ADD FOREIGN KEY (parent_id) REFERENCES category (id);
ALTER TABLE Categories ADD FOREIGN KEY (child_id) REFERENCES category (id);

Table data:

INSERT INTO Category(id, name) VALUES (1, 'parent_1');
INSERT INTO Category(id, name) VALUES (2, 'child_1');
INSERT INTO Category(id, name) VALUES (3, 'child_2');
INSERT INTO Category(id, name) VALUES (4, 'child_3');
INSERT INTO Category(id, name) VALUES (5, 'child_1_1');
INSERT INTO Category(id, name) VALUES (6, 'child_1_2');
INSERT INTO Category(id, name) VALUES (7, 'child_1_1_1');
INSERT INTO Category(id, name) VALUES (10, 'child_of_many');
INSERT INTO Category(id, name) VALUES (11, 'parent_1');
INSERT INTO Category(id, name) VALUES (12, 'parent_2');

INSERT INTO Categories(parent_id, child_id) VALUES (1, 2);
INSERT INTO Categories(parent_id, child_id) VALUES (1, 3);
INSERT INTO Categories(parent_id, child_id) VALUES (1, 4);
INSERT INTO Categories(parent_id, child_id) VALUES (2, 5);
INSERT INTO Categories(parent_id, child_id) VALUES (2, 6);
INSERT INTO Categories(parent_id, child_id) VALUES (5, 7);

My question that the children give me, but not the children of the children etc.
If I remove the WHERE clauses, I can get all the lines:

WITH RECURSIVE categories_category AS (
  SELECT id, 'Category' AS COLUMN_TYPE, c1.name 
  FROM Category c1
  WHERE c1.id=2
UNION
  SELECT c2.id, 'Category' AS COLUMN_TYPE, c2.name
   FROM Category c1
   INNER JOIN categories cs1 ON c1.id = cs1.parent_id
   INNER JOIN Category c2 ON c2.id = cs1.child_id
   WHERE cs1.parent_id = 2
) SELECT * FROM categories_category