domingo, 13 de fevereiro de 2011

Row Count

A falta que faz um leve conhecimento de SQL:
    static int GetTableRowCount(string tableName) {
        int count = 0;
        SqlCommand cmd = new SqlCommand();
        cmd.Connection = getConn();
        cmd.CommandText = "SELECT * FROM [" + tableName + "]";
        SqlDataReader dr = cmd.ExecuteReader();
        while (dr.Read()) { 
            count += 1; 
        }
        return count;
    }

Nenhum comentário:

Postar um comentário