none
Limiting number of rows in a table using C# RRS feed

  • Question

  • Hello,

    I've created an application that is database driven. I would like to limit the number of records the user can insert into tables. I managed to do this by setting triggers on tables that count nuber of rows with every call of insert query. Yet still they can be remowved from Management Studio is it possible to put such limitation in app code so that it can not be removed? (I don't share the app code with the app user). Is ist possible simply by using the Row count method of datagrid? Thanks for any advice on this.

    Regards
    Thursday, January 22, 2009 9:50 PM

Answers

  • You can run a simple query and get the row count back. Try this.

            using (SqlConnection conn = new SqlConnection(connString))  
            {  
                using (SqlCommand cmd = new SqlCommand("SELECT COUNT(*) FROM table", conn))  
                {  
                    conn.Open();  
                    int RowCount = (int)cmd.ExecuteScalar();  
                    conn.Close();  
                }  
            } 
    • Marked as answer by Figo Fei Tuesday, January 27, 2009 7:57 AM
    Friday, January 23, 2009 3:41 AM