Beispiel #1
0
        protected void Update()
        {
            string sqlString = GetSqlVariables();

            if (sqlString == "")
            {
                lblLog.Text = $"Er zijn geen velden aangepast.";
                ShowAll();
                return;
            }
            sqlString = sqlString.Substring(0, sqlString.Length - 2);
            sqlString = "UPDATE Persons SET " + sqlString + $" WHERE ID = @ID";

            using (SqlConnection connection = new SqlConnection(GetConnection.GetConnectionString()))
            {
                SqlCommand cmd = GetCommandWithParameters(sqlString, connection);
                connection.Open();
                int rowsAffected = cmd.ExecuteNonQuery();
                lblLog.Text = rowsAffected == 0?"Deze ID bestaat niet.":$"Er zijn {rowsAffected} rijen aangepast.";
            }
            ShowAll();
        }
Beispiel #2
0
        protected void Find()
        {
            string sqlString      = "SELECT * FROM Persons WHERE Name LIKE @LikeName AND Age = @Age AND Address LIKE @LikeAddress AND City LIKE @LikeCity";
            string sqlStringNoAge = "SELECT * FROM Persons WHERE Name LIKE @LikeName AND Address LIKE @LikeAddress AND City LIKE @LikeCity";

            using (SqlConnection connection = new SqlConnection(GetConnection.GetConnectionString()))
            {
                SqlCommand cmd;
                if (txtAge.Text != "")
                {
                    cmd = GetCommandWithParameters(sqlString, connection);
                }
                else
                {
                    cmd = GetCommandWithParameters(sqlStringNoAge, connection);
                }

                connection.Open();
                GridView1.DataSource = cmd.ExecuteReader();
                GridView1.DataBind();
                lblLog.Text = $"Er zijn {GridView1.Rows.Count} records gevonden.";
            }
        }